Reputation: 5449
Hi I am starting a new project using asp.net 5.I know it is not production ready yet but what I am building will not be production ready until the end of the year so I will start with it.
I want to have a standard 3 layer architecture for the project.To that end I have created the following project structure:
Now from what I have seen online in order to register entity framework in the app I have to do the following in the Statup class of the client app:
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ProductDbContext>();
This basicly brakes the separation of concerns the client should not have any ideea what database type or data access technology the application is using. I might be missing somethign since I just started looking into asp.net 5 and entity framework 3 days ago.
Is there any way to mantain the separation of concerns using entity framework 7 and asp.net 5?
Upvotes: 0
Views: 106
Reputation: 36706
You can create extension methods of IServiceCollection in the different layers of your app to avoid having all the references in the web app.
public static class ServiceCollectionExtensions
{
public static void RegisterDbContext(this IServiceCollection services)
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ProductDbContext>();
}
}
Then, in Startup.cs:
using My.Service.Tier.ExtensionNamespace;
public void ConfigureServices(IServiceCollection services)
{
services.RegisterDbContext();
}
now your web app only needs references to your service layer instead of a direct reference to data access stuff
Upvotes: 2