-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
57 lines (53 loc) · 2.29 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using WellBites.DataAccess;
using WellBites.MVVM.ViewModels;
using WellBites.Views;
using WellBites.Models;
using WellBites.MVVM.Views;
namespace WellBites
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static readonly ServiceCollection Services = new ServiceCollection();
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var host = new HostBuilder()
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
})
.ConfigureServices((hostContext, services) =>
{
var connectionString = hostContext.Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<WellBitesDbContext>(options =>
options.UseSqlServer(connectionString));
services.AddScoped<UserManagerService>();
})
.Build();
var scope = host.Services.CreateScope();
var services = scope.ServiceProvider;
var dbContext = services.GetRequiredService<WellBitesDbContext>();
var configuration = services.GetRequiredService<IConfiguration>();
var userManagerService = services.GetRequiredService<UserManagerService>();
//dbContext.Users.RemoveRange(dbContext.Users);
//dbContext.SaveChanges();
AuthPage authPage = new AuthPage(new UserViewModel(userManagerService));
//DashboardPage page = new DashboardPage(new UserViewModel(userManagerService));
new MainWindow(authPage, configuration.GetSection("api-keys")["x-api-key"]).Show();
}
}
}