i am in big dilema..
I am working on highly modular web app in ASP.NET MVC 2 (in fact, core will be super lightweight, all work on modules/plugins). I found MEF pretty useful for modules discovery, but i dont want to us it as IoC container. There is pretty good chance that I will need advanced features of “true” IoC container, so I would like to use Unity.
And here is the problem : how to allow modules to configure container (programatically) = register their own types (mvc controllers, custom implementations of services…) at application start without making hard dependency on Unity in all modules ?
I know about Common Service Locator project, and it seems pretty good, but this interface co container only allows resolving types, not registering them (afaik).
I really hope you can understand my point, I know my english is terrible (I am from non english speaking country 🙂
Thanks a lot !
I can certainly sympathize with not wanting to use MEF as a DI Container, but I think you should still consider whether that might not be applicable for your add-ins.
You already require your add-ins to use MEF, so they will all have a hard dependency on it. While I personally don’t like the hard-coded, attribute-based approach used by MEF, it sounds like you are asking how each add-in can register itself with the DI Container. That also sounds like hard-coding to me, so you might as well just use MEF all the way in.
Applying MEF attributes is component registration.
If you really don’t want to use MEF you only have a few other options (none of them particularly more attractive):
Using MEF for add-ins doesn’t preclude you from using Unity in your core application, but I do understand that it’s very lightweight, so that may not make a lot of sense.