[성현모] 패키지설치, DI 패턴 적용.

This commit is contained in:
SHM
2026-03-09 11:02:41 +09:00
parent 0b476f4072
commit 2c2c94f6fa
13 changed files with 88 additions and 31 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -7,18 +7,15 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Logging">
<HintPath>..\DLL\Microsoft.Extensions.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
<HintPath>..\DLL\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\DLL\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SystemX.Core">
<HintPath>..\DLL\SystemX.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Update="Config\LogXnetConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,10 +1,17 @@
using eCIAv2.WindowsApp.ViewModels;
namespace eCIAv2.WindowsApp
{
public partial class MainForm : Form
{
public MainForm()
private readonly MainFromViewModel _vm;
public MainForm(MainFromViewModel vm)
{
InitializeComponent();
_vm = vm;
var ss= _vm.LoadConfig();
}
}
}

View File

@ -1,13 +1,21 @@
using eCIAv2.WindowsApp.Services;
using eCIAv2.WindowsApp.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace eCIAv2.WindowsApp
{
internal static class Program
{
public static IHost AppHost { get; private set; }
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//LogXnet
string configDir = @$"{Application.StartupPath}Config";
//raed log4net configs
if (LogXnet.ReadConfig(@$"{configDir}/LogXnetConfig.json") == true)
@ -20,10 +28,23 @@ namespace eCIAv2.WindowsApp
return;
}
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
AppHost = Host.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
// services
services.AddSingleton<ConfigService>();
//viewmodels
services.AddTransient<MainFromViewModel>();
// forms
services.AddTransient<MainForm>();
}).Build();
ApplicationConfiguration.Initialize();
Application.Run(new MainForm());
var form = AppHost.Services.GetRequiredService<MainForm>();
Application.Run(form);
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace eCIAv2.WindowsApp.Services
{
public class ConfigService
{
public string LoadConfig()
{
return "loadConfig";
}
}
}

View File

@ -0,0 +1,24 @@
using eCIAv2.WindowsApp.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace eCIAv2.WindowsApp.ViewModels
{
public class MainFromViewModel
{
private readonly ConfigService _configService;
public MainFromViewModel(ConfigService configService)
{
_configService = configService;
}
public string LoadConfig()
{
return _configService.LoadConfig();
}
}
}

View File

@ -8,29 +8,17 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\eCIAv2.Library\eCIAv2.Library.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.DependencyInjection">
<HintPath>..\DLL\Microsoft.Extensions.DependencyInjection.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
<HintPath>..\DLL\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging">
<HintPath>..\DLL\Microsoft.Extensions.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
<HintPath>..\DLL\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Options">
<HintPath>..\DLL\Microsoft.Extensions.Options.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\DLL\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SystemX.Core">
<HintPath>..\DLL\SystemX.Core.dll</HintPath>
</Reference>
@ -42,4 +30,8 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
</Project>