-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
94 lines (82 loc) · 3.23 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using DryIoc;
using MyToDo.Common;
using MyToDo.Service;
using MyToDo.ViewModels;
using MyToDo.ViewModels.Dialogs;
using MyToDo.Views;
using MyToDo.Views.Dialogs;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace MyToDo
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : PrismApplication
{
protected override Window CreateShell()
{
return Container.Resolve<MainView>(); //创建启动页,拿出启动窗口
}
public static void LoginOut(IContainerProvider containerProvider)
{
Current.MainWindow.Hide();
var dialog = containerProvider.Resolve<IDialogService>();
dialog.ShowDialog("LoginView", callback =>
{
if (callback.Result != ButtonResult.OK)
{
Environment.Exit(0);
return;
}
Current.MainWindow.Show();
});
}
protected override void OnInitialized()
{
var dialog = Container.Resolve<IDialogService>();
dialog.ShowDialog("LoginView", callback =>
{
if (callback.Result != ButtonResult.OK)
{
Environment.Exit(0);
return;
}
var service = App.Current.MainWindow.DataContext as IConfigureService;
if (service != null)
service.Configure();
base.OnInitialized();
});
}
//依赖注入的方法
//依赖容器
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.GetContainer()
.Register<HttpRestClient>(made: Parameters.Of.Type<string>(serviceKey: "webUrl"));
containerRegistry.GetContainer().RegisterInstance(@"http://localhost:3389/", serviceKey: "webUrl");
containerRegistry.Register<ILoginService, LoginService>();
containerRegistry.Register<IToDoService, ToDoService>();
containerRegistry.Register<IMemoService, MemoService>();
containerRegistry.Register<IDialogHostService, DialogHostService>();
containerRegistry.RegisterDialog<LoginView, LoginViewModel>();
containerRegistry.RegisterForNavigation<AddToDoView, AddToDoViewModel>();
containerRegistry.RegisterForNavigation<AddMemoView, AdddMemoViewModel>();
containerRegistry.RegisterForNavigation<AboutView>();
containerRegistry.RegisterForNavigation<MsgView, MsgViewModel>();
containerRegistry.RegisterForNavigation<SkinView, SkinViewModel>();
containerRegistry.RegisterForNavigation<IndexView, IndexViewModel>();
containerRegistry.RegisterForNavigation<ToDoView, ToDoViewModel>();
containerRegistry.RegisterForNavigation<MemoView, MemoViewModel>();
containerRegistry.RegisterForNavigation<SettingsView, SettingsViewModel>();
}
}
}