I have been reading a lot of sample code for DI and autofac. One thing I noticed was that many people bundle the interfaces and implementations in the same project. From design point, I believe this is not correct and all interfaces should be in separate assembly. So I define my projects like this:
UI - Web App/Windows App/Both
- Views
- Models
- Controllers/ ViewModels
Business
- Services/Processes
- Interfaces
- Model
DataAccess
- Repositories & UoW
- Interfaces
- Model
This way, my business services refer only to DataAccess interfaces and models but stay independent of actual implementation. Same way, the UI also refers to only business interfaces and model and there is clear separation. This also helps me in testing where I can independently test the layer.
My question is for Autofac Module declaration. I need to set up my build to copy the implementations into final deployment directory. My business modules need to refer to data access implementation and UI needs to access business modules.
- How should I handle this chain of dependencies in modules?
- Where should I place the module classes and how should startup code discover all the modules in easiest possible manner?
I am considering Autofac's assembly scanning but not sure if that is only option. Also note that I am already following naming convention and in most cases, I am not going to write individual bindings. My concern here is that
- since the projects referencing interfaces are unaware of implementations, I cannot write any specific bindings in the calling assembly such as the UI root assembly.
- Some sources talk about keeping the assemblies clean of any DI implementations and having separate assemblies for modules. Is that a good approach for all types of applications? (E.g. enterprise LOB app or Web App vs and ISV desktop app distributed to many independent users)