-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
73 lines (65 loc) · 2.22 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Windows;
using TodoWPF.Model;
using TodoWPF.Resource;
using TodoWPF.View;
using TodoWPF.ViewModel;
namespace TodoWPF
{
public sealed partial class App : Application
{
public App()
{
Services = ConfigureServices();
InitializeComponent();
}
/// <summary>
/// Gets the current <see cref="App"/> instance in use
/// </summary>
public new static App Current => (App)Application.Current;
/// <summary>
/// Get the unique Customer reference.
/// </summary>
public Customer Customer { get; set; }
/// <summary>
/// Gets the <see cref="IServiceProvider"/> instance to resolve application services.
/// </summary>
///
public IServiceProvider Services { get; }
/// <summary>
/// Takes the section of the main window (#Main) to display the current page.
/// </summary>
private MainWindow ThisMainWindow => (MainWindow)Application.Current.MainWindow;
/// <summary>
/// Configures the services for the application.
/// </summary>
private static IServiceProvider ConfigureServices()
{
return new ServiceCollection()
.AddTransient<MainView>()
.AddTransient<NewAccountView>()
.AddTransient<RecoverPasswordView>()
.AddSingleton<MainViewModel>()
.BuildServiceProvider();
}
/// <summary>
/// Configures the navigation for the application.
/// </summary>
public void GoTo(Endpoint endpoint)
{
switch (endpoint)
{
case Endpoint.Login:
ThisMainWindow.Main.Content = Services.GetService<MainView>();
break;
case Endpoint.SignUp:
ThisMainWindow.Main.Content = Services.GetService<NewAccountView>();
break;
case Endpoint.Recover:
ThisMainWindow.Main.Content = Services.GetService<RecoverPasswordView>();
break;
}
}
}
}