Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MEF attributes #18

Merged
merged 1 commit into from
Sep 28, 2022
Merged

Add support for MEF attributes #18

merged 1 commit into from
Sep 28, 2022

Conversation

kzu
Copy link
Contributor

@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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for MEF attributes
2 participants