-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
122 lines (97 loc) · 3.27 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Reflection;
using Caliburn.Micro;
using CrudSampleMVVM.Views;
using CrudSampleMVVM.ViewModels;
using CrudSampleMVVM.Business.Dao;
namespace CrudSampleMVVM
{
sealed partial class App : CaliburnApplication
{
// add our IOC container for registering services etc
private WinRTContainer container;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
try
{
//non capisco perchè non posso scrivere
// DatabaseConnection.Instance;
// facciamo una zezzaria per scirvere
DatabaseConnection.Singleton();
//DatabaseConnection c = DatabaseConnection.Instance;
}
catch (Exception)
{
var msgDlg = new Windows.UI.Popups.MessageDialog("Impossibile creare Database");
msgDlg.DefaultCommandIndex = 1;
msgDlg.ShowAsync();
}
}
/* starting database */
protected override void Configure()
{
container = new WinRTContainer();
container.RegisterWinRTServices();
//container.PerRequest<MainPageViewModel>();
}
/*
* AUTOMATIC REGISTRATIOn
*
*/
private static bool IsConcrete(Type service)
{
var serviceInfo = service.GetTypeInfo();
return !serviceInfo.IsAbstract && !serviceInfo.IsInterface;
}
protected override object GetInstance(Type service, string key)
{
var obj = container.GetInstance(service, key);
// mimic previous behaviour of WinRT SimpleContainer
if (obj == null && IsConcrete(service))
{
container.RegisterPerRequest(service, key, service);
obj = container.GetInstance(service, key);
}
return obj;
}
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
DisplayRootView<MainView>();
}
//protected override object GetInstance(Type service, string key)
//{
// return container.GetInstance(service, key);
//}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return container.GetAllInstances(service);
}
protected override void BuildUp(object instance)
{
container.BuildUp(instance);
}
protected override void PrepareViewFirst(Frame rootFrame)
{
container.RegisterNavigationService(rootFrame);
}
}
}