I have a solution structured like so:
- Models assembly
- Data assembly - defines repository interfaces and a base repository class
- ORM assembly - implements repository interfaces & inherits base repository class ^
- Business assembly - has a reference to the data assembly, and dynamically pulls in the ORM object via MEF (no explicit reference to the ORM assembly)
- UI assembly(s)
In this fashion, I can easily swap out the ORM, if we decide to go with something else.
I'm curious if it's possible to have similar functionality with Unity. I want to decouple my business logic from the underlying ORM. From what I've read, unity mainly works at compile time and MEF is at runtime. That being said, is it possible to decouple with unity in such a way that my business layer has no reference to the ORM, but instead just the interfaces that it implements from the data assembly? How can Unity define what implements the interface without having a reference to the implementing assembly?
Currently, with MEF, no assembly has a reference to the ORM (other than when the business layer dynamically pulls it in at runtime to discover parts and fill the interface with an object). I would prefer to continue working along these lines and would like to know if I can do that with Unity.