// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(_ => Configuration); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddMemoryCache(); services.AddDistributedMemoryCache(); SDSComApp app = new SDSComApp(); string connectionString = app.GetConnectionString(); services.AddDbContext <SDSComContext>(options => options.UseNpgsql(connectionString)); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromSeconds(3600); options.Cookie.HttpOnly = true; }); services.AddMvc(); }
//================================================================================ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { SDSComApp app = new SDSComApp(); optionsBuilder.UseNpgsql(app.GetConnectionString()); } }