/// <summary> /// Metoda specialne pro WPF aplikace, ktere nepotrebuji zadny runner, ale hodi se logovani, metriky a konfigurace /// </summary> /// <returns></returns> public ServiceCollection Build() { var services = new ServiceCollection(); // configuration var config = DefaultConfiguration.Create(configPaths.ToArray(), args); DefaultConfiguration.Configure(services, config); // app context var name = config.GetValue <string>("app:name", null); var env = config.GetValue <string>("app:env", null); var appInfo = new AppInfo(args, name, env); services.AddSingleton(appInfo); // logging var logsOptions = LogsOptions.Create(config, appInfo.Name); var(loggerFactory, defaultLogger) = DefaultLogging.Create(logsOptions, appInfo); DefaultLogging.ConfigureServices(services, loggerFactory, defaultLogger); // metrics var metricsOptions = Conventions.MetricsOptions.Create(config); IMetricsRoot metrics = DefaultMetrics.Create(metricsOptions, appInfo); DefaultMetrics.ConfigureServices(services, metrics, metricsOptions); // log few details about so far configured services for debugging purposes defaultLogger.Debug("StartUp: application {appInfo}", appInfo); defaultLogger.Debug("StartUp: logging {options}", logsOptions); defaultLogger.Debug("StartUp: metrics {options}", metricsOptions); return(services); }
public void TypeActivatorIsConfigurable() { var typeActivator = new TypeActivatorMock(); var containerBuilder = ContainerBuilder.CreateBuilder(c => { var configuration = DefaultConfiguration.Create(c); configuration.SetTypeActivator(typeActivator); return(configuration); }); containerBuilder.Register <ITestInterface1>().ImplementedBy <TestInterfaceImpl>(); var container = containerBuilder.Build(); var result = container.Resolve(typeof(ITestInterface1)); Assert.AreEqual(123, (int)result); }
private (IServiceProvider, AppInfo, ILogger) BuildImpl() { var services = new ServiceCollection(); // configuration var config = DefaultConfiguration.Create(configPaths.ToArray(), args); DefaultConfiguration.Configure(services, config); // app context var name = config.GetValue <string>("app:name", null); var env = config.GetValue <string>("app:env", null); var appInfo = new AppInfo(args, name, env); services.AddSingleton(appInfo); // logging var logsOptions = LogsOptions.Create(config, appInfo.Name); var(loggerFactory, defaultLogger) = DefaultLogging.Create(logsOptions, appInfo); DefaultLogging.ConfigureServices(services, loggerFactory, defaultLogger); // metrics var metricsOptions = Conventions.MetricsOptions.Create(config); IMetricsRoot metrics = DefaultMetrics.Create(metricsOptions, appInfo); DefaultMetrics.ConfigureServices(services, metrics, metricsOptions); // log few details about so far configured services for debugging purposes defaultLogger.Debug("StartUp: application {appInfo}", appInfo); defaultLogger.Debug("StartUp: logging {options}", logsOptions); defaultLogger.Debug("StartUp: metrics {options}", metricsOptions); // execute registered service installers foreach (var installer in installers.Values) { defaultLogger.Debug($"StartUp: service installer {installer.GetType().FullName}"); installer.Install(services, config); } var provider = services.BuildServiceProvider(validateScopes: true); return(provider, appInfo, defaultLogger); }