public void ConfigureServices(IServiceCollection services) { services.Configure <ConnectionStrings>(_configuration.GetSection("ConnectionStrings")); services.AddControllers(); services.AddAutoMapper(MappingProfilesUtility.GetProfiles()); services.AddSingleton <EntryFactory>(); services.AddTransient <IEntryService, EntryService>(); var serviceProvider = services.BuildServiceProvider(); var connectionStrings = serviceProvider.GetRequiredService <IOptions <ConnectionStrings> >(); services.AddDbContext <Database>((opts) => { opts.UseNpgsql(connectionStrings.Value.Postgresql, x => x.MigrationsAssembly("Perconall.PublicApi")); }); serviceProvider.Dispose(); services.AddSingleton <IMessageQueueService, MessageQueueService>(); services.AddCors(x => { x.AddDefaultPolicy(policy => { policy.AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin(); }); }); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { services.Configure <ConnectionStrings>(hostContext.Configuration.GetSection("ConnectionStrings")); services.AddSingleton <EntryFactory>(); services.AddDbContext <Database>((opts) => { opts.UseNpgsql(hostContext.Configuration.GetSection("ConnectionStrings").GetSection("Postgresql").Value); }); services.AddAutoMapper(MappingProfilesUtility.GetProfiles()); services.AddHostedService <EntryService>(); });