Dreamine.Wpf
Ver.1.0.0
Loading...
Searching...
No Matches
DreamineAppBuilder.cs
Go to the documentation of this file.
1
using
Dreamine.MVVM.Core;
2
using
Dreamine.MVVM.Locators;
3
using
System.Reflection;
4
using
System.Windows;
5
6
namespace
Dreamine.MVVM.Wpf
7
{
11
public
static
class
DreamineAppBuilder
12
{
20
public
static
void
Initialize
(Assembly rootAssembly)
21
{
22
// ① View ↔ ViewModel 자동 매핑
23
ViewModelLocator.RegisterAll(rootAssembly);
24
25
// ② DI 자동 등록 (Model, Event, Manager, ViewModel)
26
DMContainer.AutoRegisterAll(rootAssembly);
27
28
// ③ Loaded 시 ViewModel 자동 주입
29
EventManager.RegisterClassHandler(
30
typeof(FrameworkElement),
31
FrameworkElement.LoadedEvent,
32
new
RoutedEventHandler(
AttachViewModelIfExists
));
33
}
34
41
private
static
void
AttachViewModelIfExists
(
object
sender, RoutedEventArgs e)
42
{
43
if
(sender is FrameworkElement view && view.DataContext ==
null
)
44
{
45
var vm = ViewModelLocator.Resolve(view.GetType());
46
if
(vm !=
null
)
47
{
48
view.DataContext = vm;
49
}
50
}
51
}
52
}
53
}
Dreamine.MVVM.Wpf.DreamineAppBuilder
Dreamine 앱 구동을 위한 초기화 도우미입니다.
Definition
DreamineAppBuilder.cs:12
Dreamine.MVVM.Wpf.DreamineAppBuilder.Initialize
static void Initialize(Assembly rootAssembly)
Dreamine MVVM WPF 런타임을 초기화합니다. View-ViewModel 자동 매핑, DI 자동 등록, Loaded 시점의 ViewModel 자동 주입을 구성합니다.
Definition
DreamineAppBuilder.cs:20
Dreamine.MVVM.Wpf.DreamineAppBuilder.AttachViewModelIfExists
static void AttachViewModelIfExists(object sender, RoutedEventArgs e)
WPF FrameworkElement의 Loaded 이벤트에서 호출되는 핸들러입니다. View의 DataContext가 비어 있을 경우, ViewModelLocator를 통해 Vie...
Definition
DreamineAppBuilder.cs:41
Dreamine.MVVM.Wpf
Definition
DreamineAppBuilder.cs:7
Generated by
1.14.0