How to add MEF support to a Silverlight custom control
I want to make my custom control extensible (ie master/detail, search, etc). Each instance of the custom control would request its functionality via a property.
(in开发者_如何学运维 this case it would load additional components to support master/detail).
Is this something that MEF can be used for?
Cheers
You can use mef but it might be a little clunky depending on your scenario
From you description it sounds like the custom control instance is the one who decides what additional components to load.
Mef is typically used when the target thing
doesnt know exactly what it wants, only that whatever it wants is implementing some interface (or contract to be more exact).
For instance your custom control might know that it wants to do search, but not exeactly how. Then you'd have an interface for searching, perhaps with a single Search(string) method. Your control would have a property of that type and mef would fill that in with an instance mef has found in some other assembly.
You could define contracts for the diffrent "areas" of you control and have those be filled by mef, however there are frameworks for that already, such as Prism that you should take a look at, atleast for reference.
I suggest looking over the MSDN docs for MEF and see if they apply to your scenario
精彩评论