Skip to content

Add support for new keyed service in .NET8 #73

@kzu

Description

@kzu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions