Dreamine.Wpf Ver.1.0.0
Loading...
Searching...
No Matches
DreamineAppBuilder.cs
Go to the documentation of this file.
1using Dreamine.MVVM.Core;
2using Dreamine.MVVM.Locators;
3using System.Reflection;
4using System.Windows;
5
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 앱 구동을 위한 초기화 도우미입니다.
static void Initialize(Assembly rootAssembly)
Dreamine MVVM WPF 런타임을 초기화합니다. View-ViewModel 자동 매핑, DI 자동 등록, Loaded 시점의 ViewModel 자동 주입을 구성합니다.
static void AttachViewModelIfExists(object sender, RoutedEventArgs e)
WPF FrameworkElement의 Loaded 이벤트에서 호출되는 핸들러입니다. View의 DataContext가 비어 있을 경우, ViewModelLocator를 통해 Vie...