Microsoft MVP성태의 닷넷 이야기
.NET Framework: 126.2. CAG - Shell 띄우기 [링크 복사], [링크+제목 복사],
조회: 17856
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  25  26  27  28  [29]  30  ...
NoWriterDateCnt.TitleFile(s)
12927정성태1/18/20227050개발 환경 구성: 628. AKS 환경에 응용 프로그램 배포 방법
12926정성태1/17/20227602오류 유형: 787. AKS - pod 배포 시 ErrImagePull/ImagePullBackOff 오류
12925정성태1/17/20227624개발 환경 구성: 627. AKS의 준비 단계 - ACR(Azure Container Registry)에 docker 이미지 배포
12924정성태1/15/20229159.NET Framework: 1134. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 디코딩 예제(decode_video.c) [2]파일 다운로드1
12923정성태1/15/20228035개발 환경 구성: 626. ffmpeg.exe를 사용해 비디오 파일을 MPEG1 포맷으로 변경하는 방법
12922정성태1/14/20227109개발 환경 구성: 625. AKS - Azure Kubernetes Service 생성 및 SLO/SLA 변경 방법
12921정성태1/14/20226025개발 환경 구성: 624. Docker Desktop에서 별도 서버에 설치한 docker registry에 이미지 올리는 방법
12920정성태1/14/20226824오류 유형: 786. Camtasia - An error occurred with the camera: Failed to Add Video Sampler.
12919정성태1/13/20226659Windows: 199. Host Network Service (HNS)에 의해서 점유되는 포트
12918정성태1/13/20226899Linux: 47. WSL - shell script에서 설정한 환경 변수가 스크립트 실행 후 반영되지 않는 문제
12917정성태1/12/20226006오류 유형: 785. C# - The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
12916정성태1/12/20225815오류 유형: 784. TFS - One or more source control bindings for this solution are not valid and are listed below.
12915정성태1/11/20226090오류 유형: 783. Visual Studio - We didn't find any interpreters
12914정성태1/11/20228140VS.NET IDE: 172. 비주얼 스튜디오 2022의 파이선 개발 환경 지원
12913정성태1/11/20228628.NET Framework: 1133. C# - byte * (바이트 포인터)를 FileStream으로 쓰는 방법 [1]
12912정성태1/11/20229308개발 환경 구성: 623. ffmpeg.exe를 사용해 비디오 파일의 이미지를 PGM(Portable Gray Map) 파일 포맷으로 출력하는 방법 [1]
12911정성태1/11/20226474VS.NET IDE: 171. 비주얼 스튜디오 - 더 이상 만들 수 없는 "ASP.NET Core 3.1 Web Application (.NET Framework)" 프로젝트
12910정성태1/10/20226997제니퍼 .NET: 30. 제니퍼 닷넷 적용 사례 (8) - CPU high와 DB 쿼리 성능에 문제가 함께 있는 사이트
12909정성태1/10/20228367오류 유형: 782. Visual Studio 2022 설치 시 "Couldn't install Microsoft.VisualCpp.Redist.14.Latest"
12908정성태1/10/20226178.NET Framework: 1132. C# - ref/out 매개변수의 IL 코드 처리
12907정성태1/9/20226732오류 유형: 781. (youtube-dl.exe) 실행 시 "This app can't run on your PC" / "Access is denied." 오류 발생
12906정성태1/9/20227385.NET Framework: 1131. C# - 네임스페이스까지 동일한 타입을 2개의 DLL에서 제공하는 경우 충돌을 우회하는 방법 [1]파일 다운로드1
12905정성태1/8/20227037오류 유형: 780. Could not load file or assembly 'Microsoft.VisualStudio.TextTemplating.VSHost.15.0, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
12904정성태1/8/20229028개발 환경 구성: 623. Visual Studio 2022 빌드 환경을 위한 github Actions 설정 [1]
12903정성태1/7/20227639.NET Framework: 1130. C# - ELEMENT_TYPE_INTERNAL 유형의 사용 예
12902정성태1/7/20227678오류 유형: 779. SQL 서버 로그인 에러 - provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.
... 16  17  18  19  20  21  22  23  24  25  26  27  28  [29]  30  ...