MEF - change default creation policy for NonShared

I am currently working on using MEF to scan / link extensions for my applications. I would like to change the default creation policy to not general (instead of general), but have it so that the creation policy is redefined through attributes. In other words, if I do not specify a creation policy for export, I want MEF to use non-generic ones.

My previous implementation no longer works for me, because it changes the required creation policy for all imports. Therefore, if I override the creation policy, the export is not linked.

I searched around and closest I was able to get a new RegisrationBuilder, but I am working with .NET 4 (so MEF 1) in VS2010. I also could not find a way with ExportProviders.

Any help is appreciated; thanks in advance!

+4
source share
1 answer

I managed to create a MEF wrapper that I use as an application bootstrap. In projects where I use MEF, I have custom mu attributes that I use to control instes instance mode. Custom attribute implementation will be:

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] public class BusinessLogicImportAttribute : ConstraintImportAttribute { public BusinessLogicImportAttribute() : base(typeof(IBusinessController)) { base.RequiredCreationPolicy = RequiredCreationPolicy = CreationPolicy.NonShared; } } 
0
source

All Articles