Dapper.Extensions
Dapper.Extensions copied to clipboard
.NET DI differentiation using Keyed Services
As of .NET 8 you can now register services using keys.
services.AddKeyedSingleton<IMessageWriter, MemoryMessageWriter>("memory");
services.AddKeyedSingleton<IMessageWriter, QueueMessageWriter>("queue");
public class ExampleService
{
public ExampleService(
[FromKeyedServices("queue")] IMessageWriter writer)
{
// Omitted for brevity...
}
}
Please consider allowing .NET DI to have the same function as autofac
Thank you for your suggestion. I tried this feature when .net 8 first supported it. Because .NET DI cannot pass constant parameters to the constructor, such as whether to enable read-write separation, I finally decided to continue using autofac.