I am new to Asp.Net Core and EF. I am developing a simple CRUD from database-end, using the Secrets.json
file to hide my connection string credentials.
But I don't know how to reference the file using AddDbContext().
My code so far:
public class Startup
{
public Startup(IConfigurationRoot configuration)
{
Configuration = configuration;
}
public IConfigurationRoot Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<POTS.myDBContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("myConxStr")));
services.AddControllers();
}
When the code runs, I get this error on the AddDbContext<>
line
System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. (Parameter 'connectionString')
Source=Microsoft.EntityFrameworkCore.SqlServer StackTrace: etc etc
I think this is because the code is looking for the parameter in the appsettings.json
file, where I don't want the connectionstring to be.
What am I missing?