-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
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
Singletonfor[Service], and transient for[Export]unless a[PartCreationPolicy(CreationPolicy.Shared)]is used (to keep MEF conventions).