Microsoft MVP성태의 닷넷 이야기
.NET Framework: 126.2. CAG - Shell 띄우기 [링크 복사], [링크+제목 복사],
조회: 17742
글쓴 사람
정성태 (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)
13367정성태6/10/20233682오류 유형: 864. openssl로 만든 pfx 인증서를 Windows Server 2016 이하에서 등록 시 "The password you entered is incorrect" 오류 발생
13366정성태6/10/20233434.NET Framework: 2128. C# - 윈도우 시스템에서 지원하는 암호화 목록(Cipher Suites) 나열파일 다운로드1
13365정성태6/8/20233147오류 유형: 863. MODIFY FILE encountered operating system error 112(failed to retrieve text for this error. Reason: 15105)
13364정성태6/8/20233980.NET Framework: 2127. C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 [1]
13363정성태6/7/20233567스크립트: 49. 파이썬 - "Transformers (신경망 언어모델 라이브러리) 강좌" - 1장 2절 코드 실행 결과
13362정성태6/1/20233525.NET Framework: 2126. C# - 서버 측의 요청 제어 (Microsoft.AspNetCore.RateLimiting)파일 다운로드1
13361정성태5/31/20233883오류 유형: 862. Facebook - ASP.NET/WebClient 사용 시 graph.facebook.com/me 호출에 대해 403 Forbidden 오류
13360정성태5/31/20233239오류 유형: 861. WSL/docker - failed to start shim: start failed: io.containerd.runc.v2: create new shim socket
13359정성태5/19/20233565오류 유형: 860. Docker Desktop - k8s 초기화 무한 반복한다면?
13358정성태5/17/20233952.NET Framework: 2125. C# - Semantic Kernel의 Semantic Memory 사용 예제 [1]파일 다운로드1
13357정성태5/16/20233794.NET Framework: 2124. C# - Semantic Kernel의 Planner 사용 예제파일 다운로드1
13356정성태5/15/20234135DDK: 10. Device Driver 테스트 설치 관련 오류 (Code 37, Code 31) 및 인증서 관련 정리
13355정성태5/12/20234076.NET Framework: 2123. C# - Semantic Kernel의 ChatGPT 대화 구현 [1]파일 다운로드1
13354정성태5/12/20234246.NET Framework: 2122. C# - "Use Unicode UTF-8 for worldwide language support" 설정을 한 경우, 한글 입력이 '\0' 문자로 처리
13352정성태5/12/20233889.NET Framework: 2121. C# - Semantic Kernel의 대화 문맥 유지파일 다운로드1
13351정성태5/11/20234375VS.NET IDE: 185. Visual Studio - 원격 Docker container 내에 실행 중인 응용 프로그램에 대한 디버깅 [1]
13350정성태5/11/20233649오류 유형: 859. Windows Date and Time - Unable to continue. You do not have permission to perform this task
13349정성태5/11/20233964.NET Framework: 2120. C# - Semantic Kernel의 Skill과 Function 사용 예제파일 다운로드1
13348정성태5/10/20233871.NET Framework: 2119. C# - Semantic Kernel의 "Basic Loading of the Kernel" 예제
13347정성태5/10/20234275.NET Framework: 2118. C# - Semantic Kernel의 Prompt chaining 예제파일 다운로드1
13346정성태5/10/20234108오류 유형: 858. RDP 원격 환경과 로컬 PC 간의 Ctrl+C, Ctrl+V 복사가 안 되는 문제
13345정성태5/9/20235527.NET Framework: 2117. C# - (OpenAI 기반의) Microsoft Semantic Kernel을 이용한 자연어 처리 [1]파일 다운로드1
13344정성태5/9/20236652.NET Framework: 2116. C# - OpenAI API 사용 - 지원 모델 목록 [1]파일 다운로드1
13343정성태5/9/20234569디버깅 기술: 192. Windbg - Hyper-V VM으로 이더넷 원격 디버깅 연결하는 방법
13342정성태5/8/20234433.NET Framework: 2115. System.Text.Json의 역직렬화 시 필드/속성 주의
13341정성태5/8/20234158닷넷: 2114. C# 12 - 모든 형식의 별칭(Using aliases for any type)
1  2  3  4  5  6  7  8  9  10  [11]  12  13  14  15  ...