diff --git a/Client/App.xaml.cs b/Client/App.xaml.cs index 0afd92e..3e1ed5d 100644 --- a/Client/App.xaml.cs +++ b/Client/App.xaml.cs @@ -11,6 +11,8 @@ using Client.Domain.Entities; using Client.Domain.Service; using BaseApp = System.Windows.Application; using Client.Domain.ValueObjects; +using Microsoft.Extensions.Configuration; +using System.Reflection; namespace Client { @@ -20,38 +22,14 @@ namespace Client public partial class App : BaseApp { public static IHost? AppHost { get; private set; } + public static IConfiguration? AppConfig { get; private set; } public App() { AppHost = Host.CreateDefaultBuilder() - .ConfigureServices((hostContext, services) => { - services - .AddSingleton() - .AddSingleton( - typeof(Application), - x => new Application( - x.GetRequiredService(), - x.GetRequiredService(), - x.GetRequiredService(), - "L2BotDll.dll" - ) - ) - .AddSingleton(typeof(EntityHandlerFactoryInterface), typeof(EntityHandlerFactory)) - .AddSingleton(typeof(MessageParserInterface), typeof(JsonMessageParser)) - .AddSingleton(typeof(TransportInterface), x => new NamedPipeTransport("PipeL2Bot")) - - .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) - .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) - .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) - .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) - .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) - - .AddSingleton>() - .AddSingleton>() - .AddSingleton>() - .AddSingleton>() - .AddSingleton(); - }) + .ConfigureServices( + (hostContext, services) => ConfigureServices(services) + ) .Build(); } @@ -74,5 +52,45 @@ namespace Client base.OnExit(e); } + + private void ConfigureServices(IServiceCollection services) + { + IConfiguration config = new ConfigurationBuilder() + .AddJsonFile("config.json", optional: true, reloadOnChange: false) + .Build(); + + services + .AddSingleton(typeof(IConfiguration), config) + .AddSingleton() + .AddSingleton( + typeof(Application), + x => new Application( + x.GetRequiredService(), + x.GetRequiredService(), + x.GetRequiredService(), + config.GetValue("DLLName") ?? "" + ) + ) + .AddSingleton(typeof(EntityHandlerFactoryInterface), typeof(EntityHandlerFactory)) + .AddSingleton(typeof(MessageParserInterface), typeof(JsonMessageParser)) + .AddSingleton( + typeof(TransportInterface), + x => new NamedPipeTransport( + config.GetValue("ConnectionPipeName") ?? "" + ) + ) + + .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) + .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) + .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) + .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) + .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) + + .AddSingleton>() + .AddSingleton>() + .AddSingleton>() + .AddSingleton>() + .AddSingleton(); + } } } diff --git a/Client/Client.csproj b/Client/Client.csproj index 896b649..ff583ad 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -8,6 +8,12 @@ x86 + + + Always + + + diff --git a/Client/config.json b/Client/config.json new file mode 100644 index 0000000..b881d76 Binary files /dev/null and b/Client/config.json differ