Conversation
| { | ||
| lifetime = 0; | ||
| } | ||
| // In .NET MEF, [PartCreationPolicy(CreationPolicy.Shared)] does it. |
There was a problem hiding this comment.
unfortunately, in MEF it isn't that straightforward... whether the part is a singleton or not depends on both the Export and the Import. Nevertheless in practice, most of the times the CreationPolicy will just be Any, and if the injected object is also a singleton, then the import will also be one: https://learn.microsoft.com/en-us/dotnet/framework/mef/attributed-programming-model-overview-mef#creation-policies
Not sure what to recommend for the default behavior in this codegen, but if I were to look at our own usages, it's mostly singletons except for very few cases where we explicitly set NonShared....
There was a problem hiding this comment.
Sure, but I don't care much for MEF. This is just a "nice to have" thing, for convenience. In my (mostly VS) experience, things are almost always singletons, annotated with [PartCreationPolicy(Shared)]. There is no [NotShared] in System.Composition nor System.ComponentModel.Composition, which is why I made that the default behavior for the generator: you can only tell MEF that something is shared, so it made sense to make non-shared (transient) the default when no such attribute is present.
Fixes #17