-
I am using Mef Import attributes in some ctors like: public MyClass(
IMyInterface myType,
[Import("a")] IProvide<A> myA,
[Import("ab")] IProvide<A> myAB)
{
... Therefore I enabled the rule IContainer container = new Container(rules => rules
.WithMefAttributedModel()); --> But then I suddenly had singletons everywhere! Also for my non-mef registrations. /// <summary>Adjusts the rules to provide the full MEF compatibility.</summary>
public static Rules WithMefRules(this Rules rules)
{
var importMadeOf = rules.FactoryMethodOrSelector == null ? _defaultImportMadeOf :
Made.Of(request => GetImportingConstructor(request, rules.FactoryMethodOrSelector),
GetImportedParameter, _getImportedPropertiesAndFields);
return rules.With(importMadeOf)
.WithDefaultReuse(Reuse.Singleton)
.WithTrackingDisposableTransients();
} Why is the rule setting the default reuse to Singleton (second last line)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @zplan. It set so because Regarding non-MEF registrations - there is no distinction for them when they are already in the container registry. There was an alternative to set |
Beta Was this translation helpful? Give feedback.
Hi @zplan.
It set so because
[PartCreationPolicy(CreationPolicy.Shared)]
is the default in MEF.Regarding non-MEF registrations - there is no distinction for them when they are already in the container registry.
There was an alternative to set
Reuse.Singleton
for the specific MEF registration,but then you lose the ability to override the registration with the container rules. So there are pros and cons.