Esempio n. 1
0
        private TestServer CreateTestServer(string storageProvider, Action <IWebHostBuilder> customizeWebHost)
        {
            var loggerConfiguration = new LoggerConfiguration();

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .AddEnvironmentVariables()
                                .AddDockerSecrets(typeof(IAppConfiguration))
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .Build();

            var certificateService = IdentityConfigurationProvider.MakeCertificateService();
            var decryptionService  = new DecryptionService(certificateService);
            var appConfig          = new IdentityConfigurationProvider(configuration).GetAppConfiguration(decryptionService);

            LogFactory.ConfigureTraceLogger(loggerConfiguration, appConfig.ApplicationInsights);

            Log.Logger = loggerConfiguration.CreateLogger();



            var hostingOptions = new HostingOptions
            {
                UseIis          = false,
                UseTestUsers    = true,
                StorageProvider = storageProvider
            };

            var apiBuilder = WebHost.CreateDefaultBuilder();

            apiBuilder.ConfigureServices(c => c.AddSingleton(LdapSettings)
                                         .AddSingleton(Log.Logger)
                                         .AddSingleton(CouchDbSettings)
                                         .AddSingleton(hostingOptions)
                                         .AddSingleton(ConnectionStrings)
                                         .AddSingleton(GraphApi)
                                         .AddSingleton(ADProxy)
                                         .AddTransient <IExternalIdentityProviderSearchService, ActiveDirectoryProviderService>()
                                         .AddTransient <IExternalIdentityProviderSearchService, AzureDirectoryProviderService>()
                                         );

            customizeWebHost?.Invoke(apiBuilder);

            apiBuilder
            .ConfigureAppConfiguration((hostContext, config) =>
            {
                config.AddDockerSecrets(typeof(IAppConfiguration));
                config.SetBasePath(Directory.GetCurrentDirectory());
            })
            .UseUrls(RegistrationApiServerUrl)
            .ConfigureKestrel((context, kestrelOptions) =>
            {
            })
            .UseSerilog()
            .UseStartup <Startup>();

            return(new TestServer(apiBuilder));
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var loggerConfiguration = new LoggerConfiguration();

            //Create a builder just so that we can read the app insights instrumentation key from the config
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                                .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
                                .Build();

            var certificateService = IdentityConfigurationProvider.MakeCertificateService();
            var decryptionService  = new DecryptionService(certificateService);
            var appConfig          = new IdentityConfigurationProvider(configuration).GetAppConfiguration(decryptionService);

            LogFactory.ConfigureTraceLogger(loggerConfiguration, appConfig.ApplicationInsights);

            Log.Logger = loggerConfiguration.CreateLogger();

            try
            {
                Log.Information("Starting web host");
                CreateWebHostBuilder(args).Build().Run();

                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");

                Environment.Exit(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }