c# - Arranging dotnet core app for 3-tiers with data access layer -


my typical .net 4.5x web application structure has minimum of 3 tiers: web project (a .net web application), domain/business logic project (a class library), , data access project (a class library). web project references business layer, , business layer references data access layer.

i approach since web project not have reference data access project (it must go through domain/business logic layer first). web project shouldn't have access context or repository classes.

in 3-tiered .net 4.5.x app, declare connection string in web.config , give name of dbcontext name attribute of connection string.

in new dotnet core paradigm, every example see has dbcontext configured in startup.cs this:

public void configureservices(iservicecollection services) {     // add framework services.     services.addmvc();     services.addentityframework()         .addsqlserver()         .adddbcontext<myapplicationcontext>("myconnectionstring  or reference it"); } 

by giving startup concrete class use dbcontext, must reference data access project, dbcontext defined. prefer reference middle tier, , avoid reference dal.

my question is: how should arrange solution structure can avoid adding reference web project data access project?

can use appsettings.json property?

can add entity configuration way?

is there major missing dot net core?

thank in advance.

i found solution using ef6 , dotnet core comfortable with.

it doesn't use services.addsqlserver() call ef7, rather uses ef6 configuration , registers dbcontext in bootstrap class called @ startup.

public static class bootstrapconfig {     public static void registerapplicationservices(this iservicecollection services, iconfigurationroot configuration)     {         // dbcontext         services.addscoped<dbcontext>(x => new applicationcontext(configuration["data:applicationcontext:connectionstring"]));     } } 

this called startup.cs in weblibrary project

public void configureservices(iservicecollection services) {     // add framework services.     services.addmvc();      services.registerapplicationservices(configuration); } 

enter image description here

weblibrary dot net core web application (contains controllers, startup project).

business logic service layer, , middle tier between web app , data access project.

data access dbcontext , repository classes exist doing query.

the model project holds pocos , enums, not smart objects containers used across application.

the bootstrap project has reference both business logic , data access projects can register services , repositories ioc container.

check out github repo example solution. one problem still have, specific application this:

even though web library not have reference data access project, can still instantiate applicationcontext 1 of controllers. whole point of separating these projects out make impossible db context directly in web project. i'm not sure if that's related new solution structure in core or if i'm including unaware of.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -