// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); builder.SetBasePath(env.ContentRootPath) //add configuration.json .AddJsonFile("configuration.json", optional: false, reloadOnChange: true) .AddEnvironmentVariables(); Configuration = builder.Build(); }
public void Start() { var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder() .AddCommandLine(new[] { "--server.urls", $"http://{_serverInterface}:{_serverPort}" }); var builder = new WebHostBuilder() .UseKestrel() .ConfigureServices(serviceCollection => { serviceCollection.AddSingleton(_environment); serviceCollection.AddSingleton(_sharedTextWriter); serviceCollection.AddSingleton(NullEventEmitter.Instance); serviceCollection.AddSingleton(_commandLinePlugins); serviceCollection.AddSingleton(new HttpEnvironment { Port = _serverPort }); }) .UseUrls($"http://{_serverInterface}:{_serverPort}") .UseConfiguration(config.Build()) .UseEnvironment("OmniSharp") .UseStartup(typeof(Startup)); using (var app = builder.Build()) { app.Start(); var appLifeTime = app.Services.GetRequiredService <IHostApplicationLifetime>(); Console.CancelKeyPress += (sender, e) => { appLifeTime.StopApplication(); e.Cancel = true; }; if (_environment.HostProcessId != -1) { try { var hostProcess = Process.GetProcessById(_environment.HostProcessId); hostProcess.EnableRaisingEvents = true; hostProcess.OnExit(() => appLifeTime.StopApplication()); } catch { // If the process dies before we get here then request shutdown // immediately appLifeTime.StopApplication(); } } appLifeTime.ApplicationStopping.WaitHandle.WaitOne(); } }
public static ApplicationSettings CreateInMemoryApplicationSettingsStandard(string name) { //if (configurationRoot == null) //{ var configurationBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); Microsoft.Extensions.Configuration.JsonConfigurationExtensions.AddJsonFile(configurationBuilder, "appsettings.json", optional: false, reloadOnChange: true); Microsoft.Extensions.Configuration.IConfiguration configurationRoot = configurationBuilder.Build(); //} var appSettings = new Routines.Configuration.Standard.AppSettings(configurationRoot); var configurationManagerLoader = new Routines.Configuration.Standard.ConfigurationManagerLoader(configurationRoot); var configurationContainerFactory = ResetConfigurationContainerFactoryStandard(configurationManagerLoader); var unhandledExceptionLogging = new NUnhandledExceptionLogging(); return(new ApplicationSettings(appSettings, configurationContainerFactory, unhandledExceptionLogging, new AdminkaStorageConfiguration(name, null, StorageType.INMEMORY, null))); }
public static ApplicationSettings CreateApplicationSettingsStandard(Microsoft.Extensions.Configuration.IConfiguration configurationRoot = null, string migrationAssembly = null) { if (configurationRoot == null) { var configurationBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); Microsoft.Extensions.Configuration.JsonConfigurationExtensions.AddJsonFile(configurationBuilder, "appsettings.json", optional: false, reloadOnChange: true); configurationRoot = configurationBuilder.Build(); } var connectionStringMap = new Routines.Configuration.Standard.ConnectionStringMap(configurationRoot); var connectionString = connectionStringMap.GetConnectionString("AdminkaConnectionString"); var adminkaStorageConfiguration = new AdminkaStorageConfiguration(connectionString, migrationAssembly, StorageType.SQLSERVER, migrationAssembly == null?default(int?):5 * 60); var appSettings = new Routines.Configuration.Standard.AppSettings(configurationRoot); var configurationManagerLoader = new Routines.Configuration.Standard.ConfigurationManagerLoader(configurationRoot); var configurationContainerFactory = ResetConfigurationContainerFactoryStandard(configurationManagerLoader); var unhandledExceptionLogging = new NUnhandledExceptionLogging(); return(new ApplicationSettings(appSettings, configurationContainerFactory, unhandledExceptionLogging, adminkaStorageConfiguration)); }
public void AddMongoDbContext_WithConfiguration() { var configurationBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); configurationBuilder.Add(new Microsoft.Extensions.Configuration.Memory.MemoryConfigurationSource { InitialData = new Dictionary <string, string> { { "ConnectionString", MongoDbDefaults.LocalConnectionString }, { "DatabaseName", "test" }, { "CamelCase", "true" }, { "IgnoreIfNull", "true" } } }); var configuration = configurationBuilder.Build(); var services = new ServiceCollection(); services .AddSingleton <TestService>() .AddMongoDbContext <TestDbContext>(configuration) .AddFakeMongoDbClientFactory(); using (var scope = services.BuildServiceProvider()) { var dbContext = scope.GetService <TestDbContext>(); var pack = ConventionRegistry.Lookup(typeof(Document)); Assert.NotEmpty(pack.Conventions.OfType <CamelCaseElementNameConvention>()); Assert.NotEmpty(pack.Conventions.OfType <IgnoreIfDefaultConvention>()); Assert.NotEmpty(pack.Conventions.OfType <IgnoreIfDefaultConvention>()); Assert.Equal("test", dbContext.Database.DatabaseNamespace.DatabaseName); dbContext.Dispose(); } }