.NET REST services, Entity Framework and loose coupling -
.NET REST services, Entity Framework and loose coupling -
i'm working on web application project using asp.net mvc3 , database in sql server. there mobile application uses info same database via rest services. here of application's layers:
model - ado.net info model, using entity framework
data access layer - repositories queries retrive info database
web application - mvc3 project, using repositories, loose coupling using construction map , di, database context gets disposed @ end of httprequest
core - layer between dal , service layer, uses repositories , exposes info service layer. sort of business logic layer.
service layer - rest services, knows core layer not dal. maps info dtos , exposes client
the problem i've got such application architecture loose coupling on service layer. service layer has reference core layer. core layer has reference info access layer , uses repositories. repositories not have default constructor though. expect 1 parameter , database object context (disposable object).
using repositories straight on website not problem. i'm using construction map , di makes loosely coupled. each context gets disposed @ end of httprequest.
the problem service layer , core layer. i'd have loose coupling there not sure how accomplish it? how inject info context , create sure gets disposed @ moment? i'd hear suggestions on how set together.
service layer has reference core layer.
that's fine.
core layer has reference info access layer , uses repositories.
that ain't fine.
your "core" should domain, business rules , logic. should not have dependencies.
start bottom of stack:
repo - no dependencies on other layers. services - dependency on core , repo. core - no dependencies on other layers. web - dependant on everything.this how it. utilize combination of interface-driven programming , dependency injection handle loose coupling.
example flow:
http request comes in (api, web tier, etc) controller found. di container sees container has dependancy onisomethingservice
, resolves it, including farther downwards dependencies (service, repo, etc). controller calls method on isomethingservice
. isomethingservice
implementation (chosen di) calls method on isomerepo
. isomerepo
implementation (chosen di) calls ef/db, returns "data-object" service. service maps "data-object" "core" object , returns controller. the instantiation of these objects should handled di container. thing missing above utilize "unit of work", wraps ef context.
entity-framework rest service datacontext loose-coupling
Comments
Post a Comment