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 new keyed service in .NET8 #73

Closed
kzu opened this issue Aug 2, 2023 · 0 comments · Fixed by #90
Closed

Add support for new keyed service in .NET8 #73

kzu opened this issue Aug 2, 2023 · 0 comments · Fixed by #90
Labels
enhancement New feature or request

Comments

@kzu
Copy link
Contributor

kzu commented Aug 2, 2023

See https://weblogs.asp.net/ricardoperes/net-8-dependency-injection-changes-keyed-services

Design:

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

@kzu kzu added the enhancement New feature or request label Aug 2, 2023
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 kzu closed this as completed in #90 Feb 29, 2024
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
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant