■ PrismApplication 클래스를 사용해 디렉토리에서 모듈을 로드하는 방법을 보여준다.
[TestLibrary 프로젝트]
▶ ViewA.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<UserControl x:Class="TestLibrary.Views.ViewA" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"> <Grid> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="36" Text="View A" /> </Grid> </UserControl> |
▶ ViewA.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 |
using System.Windows.Controls; namespace TestLibrary.Views { /// <summary> /// View A /// </summary> public partial class ViewA : UserControl { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - ViewA() /// <summary> /// 생성자 /// </summary> public ViewA() { InitializeComponent(); } #endregion } } |
▶ TestLibraryModule.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 |
using Prism.Ioc; using Prism.Modularity; using Prism.Regions; using TestLibrary.Views; namespace TestLibrary { /// <summary> /// 테스트 라이브러리 모듈 /// </summary> public class TestLibraryModule : IModule { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 초기화시 처리하기 - OnInitialized(containerProvider) /// <summary> /// 초기화시 처리하기 /// </summary> /// <param name="containerProvider">컨테이너 공급자 인터페이스</param> public void OnInitialized(IContainerProvider containerProvider) { IRegionManager regionManager = containerProvider.Resolve<IRegionManager>(); regionManager.RegisterViewWithRegion("ContentRegion", typeof(ViewA)); } #endregion #region 타입 등록하기 - RegisterTypes(containerRegistry) /// <summary> /// 타입 등록하기 /// </summary> /// <param name="containerRegistry">컨테이너 레지스트리 인터페이스</param> public void RegisterTypes(IContainerRegistry containerRegistry) { } #endregion } } |
[TestProject 프로젝트]
※ TestLibrary 프로젝트를 참조하지 않는다.
▶ App.config
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /> </startup> </configuration> |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<Window x:Class="TestProject.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:prism="http://prismlibrary.com/" Width="800" Height="600" Title="PrismApplication 클래스 : 디렉토리에서 모듈 로드하기"> <Grid> <ContentControl prism:RegionManager.RegionName="ContentRegion" /> </Grid> </Window> |
▶ MainWindow.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 |
using System.Windows; namespace TestProject.Views { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #endregion } } |
▶ MainApplication.xaml
1 2 3 4 5 6 7 |
<prism:PrismApplication x:Class="TestProject.MainApplication" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:prism="http://prismlibrary.com/"> </prism:PrismApplication> |
▶ MainApplication.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 |
using System.Windows; using Prism.Ioc; using Prism.Modularity; using Prism.Unity; using TestLibrary; using TestProject.Views; namespace TestProject { /// <summary> /// 메인 애플리케이션 /// </summary> public partial class MainApplication : PrismApplication { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 쉘 생성하기 - CreateShell() /// <summary> /// 쉘 생성하기 /// </summary> /// <returns>쉘</returns> protected override Window CreateShell() { return Container.Resolve<MainWindow>(); } #endregion #region 타입 등록하기 - RegisterTypes(containerRegistry) /// <summary> /// 타입 등록하기 /// </summary> /// <param name="containerRegistry">컨테이너 레지스트리</param> protected override void RegisterTypes(IContainerRegistry containerRegistry) { } #endregion #region 모듈 카탈로그 생성하기 - CreateModuleCatalog() /// <summary> /// 모듈 카탈로그 생성하기 /// </summary> /// <returns>모듈 카탈로그 인터페이스</returns> protected override IModuleCatalog CreateModuleCatalog() { return new DirectoryModuleCatalog() { ModulePath = @"..\..\..\TestLibrary\bin\Debug" }; } #endregion } } |
※ CreateModuleCatalog 메소드의 디렉토리 경로를 컴파일 모드에 따라 Debug와 Release로 변경할 수 있으나 예제에서는 Debug 모드로 컴파일하는 것으로 한정한다.