Microsoft MVP성태의 닷넷 이야기
.NET Framework: 126.2. CAG - Shell 띄우기 [링크 복사], [링크+제목 복사]
조회: 17700
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
부모글 보이기/감추기
(연관된 글이 3개 있습니다.)

CAG - Shell 띄우기


지난 글에서는 CAG 응용 프로그램의 빌드 환경이 설정된 솔루션을 만들어 보았는데요.

.NET : 23.1 CAG - 빌드 환경 구성
; https://www.sysnet.pe.kr/2/0/689

이어서, 가장 간단한 유형의 CAG Shell 응용 프로그램을 띄워보겠습니다. 이번 글도 역시 다음 글에서 소개된 내용의 후반부를 다룹니다.

Composite Application Guidance for WPF - June 2008
How to: Create a Solution Using the Composite Application Library
; https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ff921345(v=pandp.10)




1. Shell 정의

WPF 프로젝트에 기본 추가된 Window1 클래스의 이름 및 파일 이름을 모두 Shell로 변경하고, App.xaml 파일을 열어서 Application[@StartupUri] 속성을 제거합니다. (왜냐하면, 나중에 프로그램 코드에서 Shell 타입을 직접 로드하는 코드를 추가합니다.)

=== Shell.xaml.cs ===
public partial class Shell : Window
{
    public Shell()
    {
        InitializeComponent();
    }
}

=== App.xaml ===
<Application x:Class="DevToolManager.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
         
    </Application.Resources>
</Application>

2. Region 정의

이제, Shell 영역에서 User Control로 만들어진 View들이 활성화될 "Region"을 정의합니다. 이 구역은 향후에 제작될 View들이 위치하게 될 영역인데, 현재는 별다른 View가 정의되지 않을 것이기 때문에 다음과 같은 식으로 다소 "의미 없이" Region을 마음대로 설정해 보겠습니다.

<Window x:Class="DevToolManager.Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cal="http://www.codeplex.com/CompositeWPF"
    Title="Shell" Height="300" Width="300">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
    
        <ItemsControl cal:RegionManager.RegionName="MainRegion" />
        <ContentControl Grid.Row="1" cal:RegionManager.RegionName="StatusRegion" />
    </Grid>
</Window>

Region이라 해서 특별하게 생각하기 보다는 단순히 View가 활성화될 Container용 UserControl이라고 생각하시면 편하겠습니다.

3. bootstrapper 코드 추가

보통 WPF 응용 프로그램의 시작점이 App.xaml의 StartupUri 속성에 지정된 타입인 반면, CAG에서는 이것을 Bootstrapper 타입에서 결정합니다. 물론, 이름이야 바꿀 수 있겠지만, CAG의 기존 클래스명이 그러하니 아래에서도 그대로 정의해 보았습니다.

=== Bootstrapper.cs 파일 추가 ====

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.UnityExtensions;
using System.Windows;

namespace DevToolManager
{
    public class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            Shell shell = Container.Resolve<Shell>();
            shell.Show();
            return shell;
        }
    }
}

Bootstrapper를 완성했으니, 이를 이용해서 직접 Shell을 구동해야 할텐데요. 그냥... App.OnStartup에서 이 작업을 해주면 되겠습니다.

namespace DevToolManager
{
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Bootstrapper bootstrapper = new Bootstrapper();
            bootstrapper.Run();
        }

    }
}

사실, 지금까지의 코드를 보면 단순히 Shell 타입을 App.StartupUri 속성에 지정하지 않고 수동으로 로드시키는 작업과 비교해보면 크게 다르지 않습니다. CAG 응용 프로그램에서의 차별화된 점이라면, 여기서 반드시 UnityFramework에 의해서 "관리"를 받게 될 모듈들을 정의해야 한다는 제약이 있습니다. (그렇지 않으면 실행 시에 모듈이 지정되지 않았다는 런타임 오류가 발생합니다.)

모듈을 로드하는 방식은 다음과 같이 4가지로 다양하게 준비되어 있습니다.

  • 코드로 모듈 추가: 코드 상에서 직접 대상 모듈을 추가한다. 물론, 이런 경우 해당 어셈블리에 대한 정적 참조를 하고 있어야 한다.
  • XAML 파일에서 모듈 추가: ModuleCatalog.xaml을 이용하여 추가될 모듈 정의
  • App.Config에서 모듈 추가
  • 디렉터리에서 모듈 추가: 모듈을 담고 있는 어셈블리가 있는 폴더를 지정

프레임워크에 포함될 기반 라이브러리는 어차피 참조를 해서 관리를 하는 것이 편하기 때문에 그런 경우에는 코드로 모듈을 추가하면 되지만, 그 이외의 업무를 담당하는 어셈블리들은 ModuleCatalog.XAML 또는 app.config에 모듈을 추가하면 됩니다. 상식이라고 생각되긴 하지만, 혹시나 싶어 한마디 하자면, 절대 (사실 절대까지는 아니지만!) 업무용 어셈블리를 참조 추가해서 코드상에서 모듈을 추가하지 마십시오. 당장 지금 편하다고 해서 코드로 모듈을 추가하는 것은 나중에 프로젝트 규모가 커지면 사실상 "참조 지옥(Circular Reference Hell)"을 불러일으키기 때문입니다.

일단, 나중에 바꾸겠지만 별다르게 모듈이 정의되지 않은 현재 상태에서 런타임 오류를 없애기 위해 디렉터리를 지정함으로써 모듈을 추가하는 방식을 사용하는 코드를 추가하겠습니다. 코드 정의는 다음과 같이 "Bootstrapper" 타입 안에서 GetModuleCatalog를 재정의하는 것으로 완료됩니다.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.UnityExtensions;
using System.Windows;
using Microsoft.Practices.Composite.Modularity;
using System.IO;

namespace DevToolManager
{
    public class Bootstrapper : UnityBootstrapper
    {
		...[중간생략]...

        protected override Microsoft.Practices.Composite.Modularity.IModuleCatalog GetModuleCatalog()
        {
            string modulePath = @".\Modules";
            if (Directory.Exists(modulePath) == false)
            {
                Directory.CreateDirectory(modulePath);
            }
            
            return new DirectoryModuleCatalog() { ModulePath = modulePath };
        }
    }
}

오늘은 여기까지만!

*** 첨부된 압축 파일은, 위의 과정을 완료한 예제 솔루션입니다.




[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 7/17/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13608정성태4/26/202439닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?파일 다운로드1
13607정성태4/25/2024216닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/2024229닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/2024506닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/2024572오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/2024773닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/2024842닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/2024881닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
13600정성태4/18/2024905닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/2024878닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/2024909닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드2
13597정성태4/15/2024892닷넷: 2239. C# - WAV 파일의 PCM 데이터 생성 및 출력파일 다운로드1
13596정성태4/14/20241077닷넷: 2238. C# - WAV 기본 파일 포맷파일 다운로드1
13595정성태4/13/20241058닷넷: 2237. C# - Audio 장치 열기 (Windows Multimedia, NAudio)파일 다운로드1
13594정성태4/12/20241074닷넷: 2236. C# - Audio 장치 열람 (Windows Multimedia, NAudio)파일 다운로드1
13593정성태4/8/20241088닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/20241226C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동
13591정성태4/2/20241201닷넷: 2234. C# - WPF 응용 프로그램에 Blazor App 통합파일 다운로드1
13590정성태3/31/20241081Linux: 70. Python - uwsgi 응용 프로그램이 k8s 환경에서 OOM 발생하는 문제
13589정성태3/29/20241158닷넷: 2233. C# - 프로세스 CPU 사용량을 나타내는 성능 카운터와 Win32 API파일 다운로드1
13588정성태3/28/20241273닷넷: 2232. C# - Unity + 닷넷 App(WinForms/WPF) 간의 Named Pipe 통신 [2]파일 다운로드1
13587정성태3/27/20241358오류 유형: 900. Windows Update 오류 - 8024402C, 80070643
13586정성태3/27/20241529Windows: 263. Windows - 복구 파티션(Recovery Partition) 용량을 늘리는 방법
13585정성태3/26/20241313Windows: 262. PerformanceCounter의 InstanceName에 pid를 추가한 "Process V2"
13584정성태3/26/20241273개발 환경 구성: 708. Unity3D - C# Windows Forms / WPF Application에 통합하는 방법파일 다운로드1
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...