I have been using MEF for some time, and the key factor when we use it instead of IOC products is that we regularly have 3-5 implementations of this interface, which are in our plugins directory at a given time. Which of these implementations should be used is something that can only be solved at runtime.
MEF can let you do just that. As a rule, the IOC is oriented so that you can swap, for a conical example, an IUserRepository based on the ORM 1 product for the ORM 2 product at some point in the future. However, most IOC decisions suggest that only one IUserRepository will be in effect at a given time.
If, however, you need to select one based on the input for a given page request, IOC containers are usually lost.
As an example, we check our rights and our check through MEF plugins for a large web application that I have been working on for some time. Using MEF, we can see when the CreateOn date is recorded and go to the validation plugin that actually acted when the record was created, and start the BOTH record through this plugin AND validator, which is currently valid, and compare the record's validity over time.
This type of power also allows us to define pattern overflows for plugins. The applications I'm working on are actually the same code base that was deployed for 30+ implementations. So, we usually look for plugins asking for:
- An interface implementation that is specific to the current site and specific record type.
- An interface implementation specific to the current site, but working with any type of record.
- An interface that works for any site and any entry.
This allows us to combine the set of default plugins that will be involved, but only if this particular implementation does not cancel it with specific client rules.
IOC is a great technology, but it seems to make it easier to code interfaces instead of specific implementations. However, replacing these implementations is more likely a type of project event in the IOC. In MEF, you take on the flexibility of interfaces and specific implementations, and you do this with the runtime of many of the available parameters.
J Wynia Sep 10 '11 at 20:14 2011-09-10 20:14
source share