refactor(P5a): App DI 컴포지션 루트 + MainWindow 생성자 주입 (서비스로케이터 제거)
MVVM(P5b)의 선행조건 — 엔진/설정을 생성자 주입으로 가시화하고 서비스로케이터 결합을 제거. - App.xaml.cs: new DpapiSettingsStore()+CreateDefault() 직접 생성 → ServiceCollection.AddEverything2Everything() (P2 DI 재사용) 컴포지션 루트. Settings/Engine은 컨테이너 단일 싱글턴에서 해소(공유 보존). Generic Host 대신 ServiceProvider 사용 — Environment.Exit 진입점과 라이프사이클 충돌 회피(적대적 리뷰 반영). - MainWindow: ((App)Application.Current).Engine/.Settings 서비스로케이터 8곳 → 생성자 주입 _engine/_settings. App.ShowMainWindow/ShowConvertDialog가 주입. 헤드리스 테스트 가능성 토대. 70개 테스트 전부 그린, 빌드 0경고/0오류.
This commit is contained in:
parent
6ce4c429fe
commit
12bda2dcbf
2 changed files with 27 additions and 16 deletions
|
|
@ -2,19 +2,27 @@ using System.Windows;
|
|||
using Everything2Everything.App.Cli;
|
||||
using Everything2Everything.App.Views;
|
||||
using Everything2Everything.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Everything2Everything.App;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
/// <summary>App·LlmProvider가 공유하는 설정 저장소 (키 저장 즉시 변환에 반영).</summary>
|
||||
public ISettingsStore Settings { get; } = new DpapiSettingsStore();
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
/// <summary>App·LlmProvider가 공유하는 설정 저장소 (키 저장 즉시 변환에 반영). DI 컨테이너 단일 싱글턴.</summary>
|
||||
public ISettingsStore Settings { get; }
|
||||
|
||||
public ConversionEngine Engine { get; }
|
||||
|
||||
public App()
|
||||
{
|
||||
Engine = Everything2EverythingBootstrap.CreateDefault(Settings);
|
||||
// 컴포지션 루트 — Core의 DI 확장(Scrutor 자동등록)으로 Provider/Registry/Engine/Settings를 구성.
|
||||
var services = new ServiceCollection();
|
||||
services.AddEverything2Everything();
|
||||
_services = services.BuildServiceProvider();
|
||||
Settings = _services.GetRequiredService<ISettingsStore>();
|
||||
Engine = _services.GetRequiredService<ConversionEngine>();
|
||||
}
|
||||
|
||||
protected override async void OnStartup(StartupEventArgs e)
|
||||
|
|
@ -68,14 +76,14 @@ public partial class App : Application
|
|||
|
||||
private void ShowMainWindow()
|
||||
{
|
||||
var window = new MainWindow();
|
||||
var window = new MainWindow(Engine, Settings);
|
||||
MainWindow = window;
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private void ShowConvertDialog(IReadOnlyList<string> files)
|
||||
{
|
||||
var window = new Views.MainWindow(files);
|
||||
var window = new Views.MainWindow(Engine, Settings, files);
|
||||
MainWindow = window;
|
||||
window.Show();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue