-
Notifications
You must be signed in to change notification settings - Fork 2
/
TodoMvcBootstrapper.cs
116 lines (95 loc) · 3.79 KB
/
TodoMvcBootstrapper.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
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.Windows;
using Urunium.Redux;
using Urunium.Redux.Compose;
using Urunium.Redux.Logic;
using WpfTodoMvcExample.Fx.CustomTriggers;
using WpfTodoMvcExample.Logics;
using WpfTodoMvcExample.Reducers;
using WpfTodoMvcExample.States;
namespace WpfTodoMvcExample.Fx
{
/// <summary>
/// Bootstrapper for caliburn-micro application.
/// </summary>
public class TodoMvcBootstrapper : BootstrapperBase
{
private SimpleContainer _container;
/// <summary>
/// Create an instance of TodoMvcBootstrapper.
/// </summary>
public TodoMvcBootstrapper()
{
_container = new SimpleContainer();
Initialize();
}
protected override void BuildUp(object instance)
{
_container.BuildUp(instance);
}
protected override void Configure()
{
AddCustomEventTriggers();
_container.Singleton<IWindowManager, WindowManager>();
var rootReducer = new ReducerComposer<TodoList>()
.AddSubTreeReducer(new TodoItemsReducer())
.AddSubTreeReducer(new EditingTodoItemsReducer())
.AddSubTreeReducer(new VisibilityFilterReducer());
IStore<TodoList> Store = (new Store<TodoList>(rootReducer, TodoList.InitialState)).ConfigureLogic(config =>
{
config.AddLogics(new UpdateTodoTextHandler());
config.AddLogics(new AddTodoHandler());
});
_container.Instance(Store);
_container.PerRequest<IShell, ShellViewModel>();
_container.PerRequest<TodoListAppViewModel>();
_container.PerRequest<TodoItemViewModel>();
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return _container.GetAllInstances(service);
}
protected override object GetInstance(Type service, string key)
{
return _container.GetInstance(service, key);
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
dynamic settings = new System.Dynamic.ExpandoObject();
settings.Height = 700;
settings.Width = 600;
settings.SizeToContent = SizeToContent.Manual;
settings.Title = "Todo MVC";
DisplayRootViewFor<IShell>(settings);
}
private void AddCustomEventTriggers()
{
var defaultCreateTrigger = Parser.CreateTrigger;
Parser.CreateTrigger = (target, triggerText) =>
{
if (triggerText == null)
{
return defaultCreateTrigger(target, null);
}
var triggerDetail = triggerText
.Replace("[", string.Empty)
.Replace("]", string.Empty);
var splits = triggerDetail.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
switch (splits[0])
{
case "Key":
var key = (System.Windows.Input.Key)Enum.Parse(typeof(System.Windows.Input.Key), splits[1], true);
return new KeyTrigger { Key = key };
case "Gesture":
var mkg = (MultiKeyGesture)(new MultiKeyGestureConverter()).ConvertFrom(splits[1]);
return new KeyTrigger { Modifiers = mkg.KeySequences[0].Modifiers, Key = mkg.KeySequences[0].Keys[0] };
case "DblClick":
return new DblClickTrigger();
}
return defaultCreateTrigger(target, triggerText);
};
}
}
}