My typical .NET 4.5X web application structure has a minimum of 3 tiers: a web project (a .NET web application), a domain/business logic project (a class library), and a data access project (a class library). The web project references the business layer, and the business layer references the data access layer.
I like this approach since my web project does not have a reference to the data access project (it must go through the domain/business logic layer first). My web project shouldn't have any access to the context or repository classes.
In the 3-tiered .net 4.5.X app, I declare the connection string in the web.config and give the name of the DbContext as the name attribute of the connection string.
In the new Dotnet Core paradigm, every example I see has the DbContext configured in the Startup.cs like this:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MyApplicationContext>("myconnectionstring or reference to it");
}
By giving the startup a concrete class to use for the dbcontext, I must reference the data access project, where the dbcontext is defined. I would prefer to only reference the middle tier, and avoid the reference to the DAL.
My question is: how should I arrange my solution structure so that I can avoid adding a reference from my web project to my data access project?
Can I use an appsettings.json property?
Can I add my Entity configuration another way?
Is there something major I am missing about dot net core?
Thank you in advance.