I have made a three-layer application with refrences going as described in this answer:
DAL with Repositories -> BLL with services and IRepository <- Asp.net mvc-app
To get this running with dependency injection I see a few options:
1. Add a reference to DAL from the web-app to be able to setup bindings on application start.
2. Use a container with xml-configuration
(3. Use reflection to load the dal-assembly and find types)
Option 1. is easy and also makes the DAL.dll be copied to bin but then I suddenly reintroduce the reference I worked so hard to get rid of. The repositories can now be accessed directly. Option 2 and 3 seems unnecessarily complex.
Is there no other way?
Using a DI Container in a Composition Root A DI Container is a software library that can automate many of the tasks involved in composing objects and managing their lifetimes. A DI Container can be misused as a Service Locator, but it should only be used as an engine that composes object graphs.
The word composition comes from the Latin componere, meaning "put together" and its meaning remains close to this. Writing classes are often called composition classes, and writing music is also called composition.
Split up the ASP.NET MVC application in two:
The resulting layering would look like this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With