Exemple #1
0
 public LetPortalBuilder(
     IServiceCollection serviceCollection,
     IConfiguration configuration,
     LetPortalOptions letPortalOptions)
 {
     Services         = serviceCollection;
     Configuration    = configuration;
     LetPortalOptions = letPortalOptions;
 }
        public static ILetPortalBuilder AddLetPortal(
            this IServiceCollection serviceCollection,
            IConfiguration configuration,
            Action <LetPortalOptions> action = null)
        {
            var letPortalOptions = new LetPortalOptions();

            if (action != null)
            {
                action.Invoke(letPortalOptions);
            }
            var corsOptions = configuration.GetSection("CorsPortalOptions").Get <Core.Configurations.CorsPortalOptions>();
            var builder     = new LetPortalBuilder(
                serviceCollection,
                configuration,
                letPortalOptions,
                corsOptions);

            return(builder);
        }
Exemple #3
0
        public static ILetPortalBuilder AddLetPortal(this IServiceCollection serviceCollection, IConfiguration configuration, Action <LetPortalOptions> action = null)
        {
            var letPortalOptions = new LetPortalOptions();

            if (action != null)
            {
                action.Invoke(letPortalOptions);
            }
            var corsOptions = configuration.GetSection("CorsPortalOptions").Get <Core.Configurations.CorsPortalOptions>();
            var builder     = new LetPortalBuilder(
                serviceCollection,
                configuration,
                letPortalOptions,
                corsOptions);

            if (letPortalOptions.EnableDatabaseConnection)
            {
                builder.Services.Configure <DatabaseOptions>(configuration.GetSection("DatabaseOptions"));
                var databaseOptions = configuration.GetSection("DatabaseOptions").Get <DatabaseOptions>();
                builder.Services.AddSingleton(databaseOptions);
                builder.SetConnectionType(databaseOptions.ConnectionType);
                if (databaseOptions.ConnectionType == ConnectionType.MongoDB)
                {
                    ConventionPackDefault.Register();
                    builder.Services.AddSingleton <MongoConnection>();
                }
            }

            if (letPortalOptions.EnableMicroservices)
            {
                builder.Services.Configure <ServiceOptions>(configuration.GetSection("ServiceOptions"));
                builder.Services.AddHttpClient <IServiceContext, ServiceContext>();
            }

            if (letPortalOptions.EnableServiceMonitor)
            {
                builder.Services.Configure <MonitorOptions>(configuration.GetSection("MonitorOptions"));
                builder.Services.AddSingleton <IMonitorHealthCheck, MonitorHealthCheck>();
                var monitorOption = configuration.GetSection("MonitorOptions").Get <MonitorOptions>();
                if (monitorOption.Enable)
                {
                    if (monitorOption.NotifyOptions.Enable)
                    {
                        builder.Services.Configure <HealthCheckPublisherOptions>(opts =>
                        {
                            opts.Delay = TimeSpan.FromSeconds(monitorOption.NotifyOptions.Delay);
                        });

                        builder.Services.AddSingleton <IHealthCheckPublisher, LetPortalMonitorHealthCheckPublisher>();
                    }
                    builder.SetHealthCheckBuilder(builder.Services.AddHealthChecks().AddCheck <LetPortalMonitorHealthCheck>(Constants.LetPortalHealthCheck));
                }
            }

            if (letPortalOptions.EnableSerilog)
            {
                builder.Services.Configure <LoggerOptions>(configuration.GetSection("LoggerOptions"));
                var serviceOptions = configuration.GetSection("ServiceOptions").Get <ServiceOptions>();
                Log.Logger = new LoggerConfiguration()
                             .ReadFrom.Configuration(configuration)
                             .Enrich.WithProperty("ServiceName", serviceOptions.Name)
                             .CreateLogger();

                builder.Services.AddSingleton(Log.Logger);
                builder.Services.AddTransient(typeof(IServiceLogger <>), typeof(ServiceLogger <>));
            }

            return(builder);
        }