So far, I have found that MEF blends well with presentation level with the following benefits.
and. DI (dependency injection)
b. Third party extension (note that all parties must use MEF or necessary wrappers)
with. Automatic detection of parts (extensions)
e. MEF allows you to extend tagging with additional metadata, which makes it easier to query and filter queries
e. Can be used to solve version problems with "dynamic link DLR and C #" or "type embedding"
Correct me if I am wrong.
I am investigating whether to use MEF in the Service layer with WCF. Pls share his experience using these two together and how does MEF help you?
Thank,
Niels
Update
. .
MEF - . , . MEF V2 ( ) , MEF V1 .
MEF - MEF , . , .
- , .
, , , IoC. , , , MEF . - , .
, WCF, - MEF WCF CodePlex, , IInstanceProvider, . , ( ), ...?
IInstanceProvider
WCF , MEF, MEF , . , , Quotation, , MEF, , . , CompositionContainer WCF (, Singleton ..). , ( , ).
CompositionContainer
, .
, MEF, WCF, . IIS. asp.net.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Global.asax .
[ImportMany(typeof(IOption))] public IEnumerable<IOption> AvailableOptions{ get; set; }
.
container.ComposeParts(this); foreach (var option in AvailableOptions) OptionRegistry.AddOption(option);
EDIT:
:
public static class OptionRegistry { private static List<IOption> _availableOptions= new List<IOption>(); public static void AddOption(IOption option) { if(!_availableOptions.Contains(option)) _availableOptions.Add(option); } public static List<IOption> GetOptions() { return _availableOptions; } }
, , .
, :
public sealed class OptionRegistry { private List<IOptionDescription> _availableOptions; static readonly OptionRegistry _instance = new OptionRegistry(); public static OptionRegistry Instance { get { return _instance; } } private OptionRegistry() { _availableOptions = new List<IOptionDescription>(); } public void AddOption(IOptionDescription option) { lock(_availableOptions) { if(!_availableOptions.Contains(option)) _availableOptions.Add(option); } } public List<IOptionDescription> GetOptions() { return _availableOptions; } }
, - WCF, , MEF, .
, , , .
, ive blogged : , WCF MEF
Hope this helps people trying to do the same.