private void InitLanguage(HomeConfiguration config) { var culture = config.GetCulture(); logger.LogInformation($"init culture: {culture}"); Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture; }
public void StartServices(HomeConfiguration config) { services = ConfigureServices(config); var loggerFactory = services .GetRequiredService <ILoggerFactory>() .AddSerilog(config.LoggerConfiguration.CreateLogger(), true); logger = loggerFactory.CreateLogger <HomeApplication>(); context = services.GetRequiredService <IServiceContext>(); InitLanguage(config); try { // notify plugins foreach (var plugin in context.GetAllPlugins(PluginsOrder.Inverse)) { logger.LogInformation($"notify plugins: {plugin.GetType().FullName}"); plugin.NotifyPlugins(); } // init plugins foreach (var plugin in context.GetAllPlugins()) { logger.LogInformation($"init plugin: {plugin.GetType().FullName}"); plugin.InitPlugin(); } // start plugins foreach (var plugin in context.GetAllPlugins()) { logger.LogInformation($"start plugin {plugin.GetType().FullName}"); plugin.StartPlugin(); } logger.LogInformation("all plugins are started"); } catch (ReflectionTypeLoadException ex) { logger.LogError(0, ex, "error on plugins initialization"); foreach (var loaderException in ex.LoaderExceptions) { logger.LogError(0, loaderException, loaderException?.Message); } throw; } catch (Exception ex) { logger.LogError(0, ex, "error on start plugins"); throw; } }
private IServiceProvider ConfigureServices(HomeConfiguration config) { var asms = config.GetDependencies().ToArray(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <ILoggerFactory, LoggerFactory>(); serviceCollection.AddSingleton <IServiceContext, ServiceContext>(); serviceCollection.AddSingleton <IConfigurationSection>(config.Configuration.GetSection("plugins")); foreach (var asm in asms) { AddAssemblyPlugins(serviceCollection, asm); } return(serviceCollection.BuildServiceProvider()); }