asp.net web api - Dependency Injection for DataContracts and Models in the BLL -
apologies if has been asked before. unable find similar question or post.
i have solution unity di framework.
i have tried understand concept of tdd , di. should last question before move things real application.
i understand concept of injecting dependency via constructor, how bll looks now:
the bll class called carservice, 1 method getcardetails:
class carservice { irepository repository; carservice(irepository repository) { this.repository = repository; } carresponse getcardetails(carrequest request) { carresponse carresponse = new carresponse(); carmodel car = this.repository.selectcarbyid(request.carid); if(car!=null) { carresponse.make = car.make; carresponse.reg = car.reg; } return carresponse; } }
using composition root (cr) suggestion in this question using webapi project cr project. wanted projects referred in cr suggested in question , here
how ever in above example code, i'll need have reference datacontracts , model project in carservice do:
carresponse carresponse = new carresponse(); carmodel car = this.repository.selectcarbyid(request.carid);
and accept carrequest method parameter.
is okay that? (this mean datacontracts , model project not referenced cr carservice)
or should resolved sort of di technique. if so, how?
it fine have contracts , models being referenced service layer. should not using dependency injection them. contracts can shared between service layer , client calling service (if .net client of course).
Comments
Post a Comment