Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Avoid Coupling with an IoC Container

I'm in the process of developing an extensible framework using DI and IoC. Users must be able override existing functionality within the framework by dropping their own implementations into the container.

How can I allow users to do this without requiring them to know which IoC container I am using?

My current half-way solution is to structure my assemblies as follows:

1) Define abstract assemblies containing only interfaces.

2) Define concrete assemblies which implement these interfaces. Users may define their own to override existing functionality.

3) Define the container bindings in separate assemblies; i.e. one binding assembly per concrete assembly.

This means the concrete assemblies are not coupled with a particular IoC container, and they would be closed against change if I used a different container. However, users are still required to know which container my framework is using in order to write the binding assemblies, and they would need to release new binding assemblies if I changed the IoC container (i.e. from Ninject to Spring).

Am I missing something?

like image 304
Lawrence Wagerfield Avatar asked Apr 26 '11 11:04

Lawrence Wagerfield


1 Answers

Write loosely coupled code. Applications should depend on containers. Frameworks should not.

like image 66
Mark Seemann Avatar answered Oct 03 '22 07:10

Mark Seemann