Apologies if this has been asked before. I was unable to find similar question or post.
I have a solution with Unity as DI Framework.
I have very recently tried to understand the concept of TDD and DI. This hopefully should be the last question before I now actually move things into my real application.
I understand the concept of injecting dependency via constructor, this is how my BLL looks like now:
The BLL Class Called CarService, with one 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 the Composition Root (CR) suggestion in this question I am using my WebAPi project as CR project. I wanted all my projects to be only referred in CR as suggested in that question and here
How ever as in above example code, I'll need to have a reference to my DataContracts and Model Project in CarService to do:
CarResponse carResponse = new CarResponse();
CarModel car = this.repository.SelectCarById(request.CarId);
and to accept CarRequest as method parameter.
Is that okay to do that? (this will mean that DataContracts and Model project is not just referenced by CR but also CarService)
or should this also be resolved by some sort of DI technique. If so, how?