c# - MEF Best practices: Where in the application I create container and where to call Compose()? -


I have decided to use MEF for a plugin pattern and it is not easy to choose MEF and at all No intrusion. I looked at the samples and found it very easy to work with them.

However, as soon as the implementation started, I started struggling with composition. Suppose I have a class in which it has [ImportMany] on one of its assets. I have seen that in all instances, they make the container in the category that has imported (let's call it composable ) and basically make the class themselves this may be fine for example, but of course the plugin can be found to know how to compute is.

I can happily make a single container and access it in my compose, but again the composer is able to call on type () and I am not happy with it because it is like a dependency injection scenario where the square actively solves () on the container so I not it Just want to use for the bus service location.

To make matters worse, I am using Windsor Castle for D. and I am not sure how MEF and Windsor should work together.

I have actually looked around and no guidance and samples were found on how to do the MEF rights. Now it can be that I have not looked around or I do not know MEF well (which is true), but in reality, using the experience in the real world will give importance to your thoughts.

Do not do this I used the MEF for my last project and I do not want to do this.

There is a good idea behind this (composition) and I was doing it manually for years. I was happy with the first official version in .NET 4.0, but there are still many design problems.

Unfortunately, this is part of Microsoft's policy that leaves testing and bugs to end users and hard-earned bugs and suggestions.

MEF Good if the way you say the instances as soon as you need a little change, you will not get enough documents and no one will reply to you. I have never solved some problems with MEF and you can find the questions that were never answered by the developer team:

1) Part of The creator (they can say ExportFactory that has been sent to the codeplex version, but I was wasting a long time on this, and I can say that it is not an acceptable solution).

2) How to set the configuration for the parts for? (I am ending the configuration in some parts through a method, which is a bad idea, but best available)

3) MEF is very slow because it Under the hood uses reflections. In my case it takes 60 seconds for 1,000 parts to load.

4) Debugging is amazing. You get ambiguous messages. You will download the full source from the codeplex and find your exceptions inside the code.

After all, I think if you have other options, then MEF will mature and use it next version.

I have shared my experience right now.

Comments