public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { hostContext.Configuration = DIModule.ConfigureJson();; services.ConfigureServices(hostContext.Configuration); services.AddScoped <DbConnectionConfigWorker>(); services.AddScoped <ConsoleWorker>(); });
public InmetricsContext CreateDbContext(string[] args) { IServiceCollection servicesCollection = new ServiceCollection(); var environment = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Development"; var configuration = DIModule.ConfigureJson(); servicesCollection.ConfigureClassesDI(configuration); var services = servicesCollection.BuildServiceProvider(); using IServiceScope serviceScope = services.CreateScope(); IOptionsSnapshot <DbConnectionConfig> options = serviceScope.ServiceProvider.GetService <IOptionsSnapshot <DbConnectionConfig> >(); var builder = new DbContextOptionsBuilder <InmetricsContext>(); builder.UseSqlServer(options.Value.GetConnectionString()); return(new InmetricsContext(options)); }