using Client.Domain.Factories; using Client.Infrastructure.Factories; using Client.Domain.Parsers; using Client.Infrastructure.Parsers; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System.Windows; using Client.Domain.Transports; using Client.Infrastructure.Transports; using Client.Domain.Entities; using Client.Domain.Service; using Client.Domain.ValueObjects; using Microsoft.Extensions.Configuration; using System.Reflection; using Client.Application.Views; using Client.Application.ViewModels; using Client.Domain.Helpers; using Client.Infrastructure.Helpers; using Client.Domain.Events; using Client.Infrastructure.Events; using System; namespace Client { /// /// Interaction logic for App.xaml /// public partial class App : System.Windows.Application { public static IHost? AppHost { get; private set; } public App() { AppHost = Host.CreateDefaultBuilder() .ConfigureServices( (hostContext, services) => ConfigureServices(services) ) .Build(); } protected override async void OnStartup(StartupEventArgs e) { await AppHost!.StartAsync(); var startupForm = AppHost.Services.GetRequiredService(); startupForm.Show(); var application = AppHost.Services.GetRequiredService(); application.StartAsync(); base.OnStartup(e); } protected override async void OnExit(ExitEventArgs e) { await AppHost!.StopAsync(); base.OnExit(e); } private void ConfigureServices(IServiceCollection services) { IConfiguration config = new ConfigurationBuilder() .AddJsonFile("config.json", optional: false, reloadOnChange: true) .AddJsonFile("Assets/data/experience.json", optional: false, reloadOnChange: true) .AddJsonFile("Assets/data/npcInfo.json", optional: false, reloadOnChange: true) .Build(); services .AddSingleton(typeof(IConfiguration), config) .AddSingleton() .AddSingleton( typeof(Bot), x => new Bot( x.GetRequiredService(), config.GetValue("DLLName") ?? "" ) ) .AddSingleton(typeof(EntityHandlerFactoryInterface), typeof(EntityHandlerFactory)) .AddSingleton(typeof(MessageParserInterface), typeof(JsonMessageParser)) .AddSingleton(typeof(OutgoingMessageBuilderInterface), typeof(JsonOutgoingMessageBuilder)) .AddSingleton( typeof(TransportInterface), x => new NamedPipeTransport( config.GetValue("ConnectionPipeName") ?? "" ) ) .AddSingleton(typeof(ExperienceHelperInterface), typeof(ConfigurationExperienceHelper)) .AddSingleton(typeof(NpcInfoHelperInterface), typeof(ConfigurationNpcInfoHelper)) .AddSingleton(typeof(EventBusInterface), typeof(InMemoryEventBus)) .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)) .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) .AddTransient(typeof(EntityFactoryInterface), typeof(ItemFactory)) .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton(); } } }