I'm trying to access a connection stored in the application. My solution has two projects, on the one hand, the database project (DAL) and on the other, the WEB API.
On the web api I have an App.settings with the connection string for the two environments.
I'm trying to configure DBContext to take the connection string from there.
What am I doing wrong?
DAL PROJECT:
DBContext:
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using DAL.Models.ProcedureModels;
using DAL;
using Microsoft.Extensions.Configuration;
..........
public DBContext()
{
}
public DBContext(DbContextOptions<DBContext> options)
: base(options)
{
}
.........
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
IConfiguration configuration;
optionsBuilder.UseSqlServer(configuration.GetConnectionString("local"));
}
}
JSON FILE IN WEB API PROJECT:
{
"ConectionStrings": {
"local": "............",
"staging": "..........",
"staging_ashure": "",
"production": ""
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}