Пример #1
0
        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .ConfigureKestrel(options => options.AddServerHeader = false)
        .ConfigureAppConfiguration((context, builder) =>
        {
            var builtConfig = builder.Build();
            if (!context.HostingEnvironment.IsDevelopment())
            {
                var keyVaultClient = FoxIDsKeyVaultClient.GetManagedClient();
                builder.AddAzureKeyVault(builtConfig["Settings:KeyVault:EndpointUri"], keyVaultClient, new DefaultKeyVaultSecretManager());
            }
        })
        .UseStartup <Startup>()
        .ConfigureLogging((context, logging) =>
        {
            var instrumentationKey = context.Configuration.GetSection("ApplicationInsights:InstrumentationKey").Value;

            if (string.IsNullOrWhiteSpace(instrumentationKey))
            {
                return;
            }

            // When not in development, remove other loggers like console, debug, event source etc. and only use ApplicationInsights logging
            if (!context.HostingEnvironment.IsDevelopment())
            {
                logging.ClearProviders();
            }

            logging.AddApplicationInsights(instrumentationKey);
        });
Пример #2
0
        public static IServiceCollection AddInfrastructure(this IServiceCollection services, Settings settings, IWebHostEnvironment env)
        {
            services.AddSharedInfrastructure();

            services.AddScoped <FoxIDsApiRouteTransformer>();

            services.AddSingleton <OidcDiscoveryHandler>();

            if (env.IsProduction())
            {
                services.AddSingleton(serviceProvider =>
                {
                    return(FoxIDsKeyVaultClient.GetManagedClient());
                });
            }
            else
            {
                services.AddTransient <TokenHelper>();
                services.AddSingleton(serviceProvider =>
                {
                    var tokenHelper = serviceProvider.GetService <TokenHelper>();
                    return(FoxIDsKeyVaultClient.GetClient(settings, tokenHelper));
                });
            }

            services.AddHttpContextAccessor();
            services.AddHttpClient();

            services.AddApiSwagger();
            services.AddAutoMapper();

            return(services);
        }
Пример #3
0
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .ConfigureKestrel(options => options.AddServerHeader = false)
 .ConfigureAppConfiguration((context, builder) =>
 {
     var builtConfig = builder.Build();
     if (context.HostingEnvironment.IsProduction())
     {
         var keyVaultClient = FoxIDsKeyVaultClient.GetManagedClient();
         builder.AddAzureKeyVault(builtConfig["Settings:KeyVault:EndpointUri"], keyVaultClient, new DefaultKeyVaultSecretManager());
     }
 })
 .UseStartup <Startup>();
Пример #4
0
        public static IServiceCollection AddInfrastructure(this IServiceCollection services, FoxIDsSettings settings, IWebHostEnvironment env)
        {
            services.AddSharedInfrastructure();

            services.AddSingleton <IStringLocalizer, FoxIDsStringLocalizer>();
            services.AddSingleton <IStringLocalizerFactory, FoxIDsStringLocalizerFactory>();
            services.AddSingleton <IValidationAttributeAdapterProvider, LocalizedValidationAttributeAdapterProvider>();

            services.AddScoped <FoxIDsRouteTransformer>();
            services.AddScoped <ICorsPolicyProvider, CorsPolicyProvider>();

            services.AddSingleton <OidcDiscoveryHandler>();

            if (env.IsProduction())
            {
                services.AddSingleton(serviceProvider =>
                {
                    return(FoxIDsKeyVaultClient.GetManagedClient());
                });
            }
            else
            {
                services.AddTransient <TokenHelper>();
                services.AddSingleton(serviceProvider =>
                {
                    var tokenHelper = serviceProvider.GetService <TokenHelper>();
                    return(FoxIDsKeyVaultClient.GetClient(settings, tokenHelper));
                });
            }

            services.AddHttpContextAccessor();
            services.AddHttpClient();

            services.AddDataProtection()
            .PersistKeysToStackExchangeRedis(ConnectionMultiplexer.Connect(settings.RedisCache.ConnectionString), "data_protection_keys");

            services.AddStackExchangeRedisCache(options => {
                options.Configuration = settings.RedisCache.ConnectionString;
                options.InstanceName  = "cache";
            });

            return(services);
        }