I have an ASP.NET Core web app and a class library project in a single solution. My intention is to use the .NET Core web app just to serve as a web application and not use as a data layer. I have created the separate class library project for the sole purpose of creating the entity classes interact with the database. And I have included the entity framework core libraries into the class library project.
How can I include multiple configuration files (based on the environment, like
appsettings.development.json
,appsettings.production.json
etc.) and read those values based on the environment I set?How can I register the
DbContext
class in the class library, like in a ASP.NET Core web app below ?
This is a snippet of my ASP.NET Core web app Startup
class
public void ConfigureServices(IServiceCollection services)
{
var connString = Configuration.GetConntectionString("ConnectionStringKey");
services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connString));
// other service configuration
}
Your input is much appreciated.