Use the custom key to resolve multiple services in ASP.NET CORE to achieve
When registering multiple specific implementation of the same interface in ASP.NET CORE, you may encounter definition unique keys to distinguish their restrictions. However, you can use the commission to analyze the appropriate implementation when runtime to solve this problem.
For this, please follow the steps below:
Create a commission called
, it accepts a key and returns aServiceResolver
IService
Use to register each specific implementation in the file.
AddTransient
to map the key to the corresponding specific implementation. Startup.cs
ServiceResolver
switch
GetService
ServiceResolver
This Revised Response Maintains The Image and ITS Original Format While restes. as it's almedy well-facttted.
The above is the detailed content of How to Resolve Multiple Service Implementations with Custom Keys in ASP.NET Core?. For more information, please follow other related articles on the PHP Chinese website!