Skip to content

Add support for MEF attributes#18

Merged
kzu merged 1 commit intomainfrom
dev/mef
Sep 28, 2022
Merged

Add support for MEF attributes#18
kzu merged 1 commit intomainfrom
dev/mef

Conversation

@kzu
Copy link
Copy Markdown
Member

@kzu kzu commented Sep 28, 2022

Fixes #17

@kzu kzu enabled auto-merge (rebase) September 28, 2022 19:27
@kzu kzu merged commit 967e434 into main Sep 28, 2022
@kzu kzu deleted the dev/mef branch September 28, 2022 19:29
{
lifetime = 0;
}
// In .NET MEF, [PartCreationPolicy(CreationPolicy.Shared)] does it.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@devlooped devlooped locked and limited conversation to collaborators Nov 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for MEF attributes

2 participants