Note that there are some explanatory texts on larger screens.

plurals
  1. PODependency Injection for DataContracts and Models in the BLL
    primarykey
    data
    text
    <p>Apologies if this has been asked before. I was unable to find similar question or post.</p> <p>I have a solution with Unity as DI Framework.</p> <p>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.</p> <p>I understand the concept of injecting dependency via constructor, this is how my BLL looks like now:</p> <p>The BLL Class Called <strong>CarService</strong>, with one method <strong>GetCarDetails</strong>:</p> <pre><code>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; } } </code></pre> <p>Using the Composition Root (CR) suggestion in <a href="https://stackoverflow.com/questions/9501604/ioc-di-why-do-i-have-to-reference-all-layers-assemblies-in-entry-application">this question</a> 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 <a href="http://blog.ploeh.dk/2011/07/28/CompositionRoot/" rel="nofollow noreferrer">here</a></p> <p>How ever as in above example code, I'll need to have a reference to my DataContracts and Model Project in CarService to do:</p> <pre><code>CarResponse carResponse = new CarResponse(); CarModel car = this.repository.SelectCarById(request.CarId); </code></pre> <p>and to accept CarRequest as method parameter.</p> <p>Is that okay to do that? (this will mean that DataContracts and Model project is not just referenced by CR but also CarService)</p> <p>or should this also be resolved by some sort of DI technique. If so, how?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload