Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        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);
        }