-
-
Notifications
You must be signed in to change notification settings - Fork 4
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 new keyed service in .NET8 #73
Labels
enhancement
New feature or request
Comments
kzu
added a commit
that referenced
this issue
Feb 29, 2024
1. A new `[Service<TKey>(key)]` attribute will be emitted. Use of the attribute reflects an explicit opt-in to keyed services and will cause a build failure if the referenced DI package isn't v8+ (seems reasonable to me). 2. Using `[FromKeyedServices]` in a type constructor will (as expected) result in resolving with the given key. 3. To keep the MEF-based decoupling in libraries, `[Export("contract")]` and `[Import("contract")]` will both be considered as hints for a string-based keyed service (both for registering and resolving, respectively). 4. Lifetime considerations remain as before: default is `Singleton` for `[Service]`, and transient for `[Export]` unless a `[PartCreationPolicy(CreationPolicy.Shared)]` is used (to keep MEF conventions). Fixes #73
kzu
added a commit
that referenced
this issue
Feb 29, 2024
1. A new `[Service<TKey>(key)]` attribute will be emitted. Use of the attribute reflects an explicit opt-in to keyed services and will cause a build failure if the referenced DI package isn't v8+ (seems reasonable to me). 2. Using `[FromKeyedServices]` in a type constructor will (as expected) result in resolving with the given key. 3. To keep the MEF-based decoupling in libraries, `[Export("contract")]` and `[Import("contract")]` will both be considered as hints for a string-based keyed service (both for registering and resolving, respectively). 4. Lifetime considerations remain as before: default is `Singleton` for `[Service]`, and transient for `[Export]` unless a `[PartCreationPolicy(CreationPolicy.Shared)]` is used (to keep MEF conventions). Fixes #73
kzu
added a commit
that referenced
this issue
Feb 29, 2024
1. A new `[Service<TKey>(key)]` attribute will be emitted. Use of the attribute reflects an explicit opt-in to keyed services and will cause a build failure if the referenced DI package isn't v8+ (seems reasonable to me). 2. Using `[FromKeyedServices]` in a type constructor will (as expected) result in resolving with the given key. 3. To keep the MEF-based decoupling in libraries, `[Export("contract")]` and `[Import("contract")]` will both be considered as hints for a string-based keyed service (both for registering and resolving, respectively). 4. Lifetime considerations remain as before: default is `Singleton` for `[Service]`, and transient for `[Export]` unless a `[PartCreationPolicy(CreationPolicy.Shared)]` is used (to keep MEF conventions). Fixes #73
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://weblogs.asp.net/ricardoperes/net-8-dependency-injection-changes-keyed-services
Design:
A new
[Service<TKey>(key)]
attribute will be emitted. Use of the attribute reflects an explicit opt-in to keyed services and will cause a build failure if the referenced DI package isn't v8+ (seems reasonable to me).Using
[FromKeyedServices]
in a type constructor will (as expected) result in resolving with the given key.To keep the MEF-based decoupling in libraries,
[Export("contract")]
and[Import("contract")]
will both be considered as hints for a string-based keyed service (both for registering and resolving, respectively).Lifetime considerations remain as before: default is
Singleton
for[Service]
, and transient for[Export]
unless a[PartCreationPolicy(CreationPolicy.Shared)]
is used (to keep MEF conventions).The text was updated successfully, but these errors were encountered: