Dapper.Extensions icon indicating copy to clipboard operation
Dapper.Extensions copied to clipboard

.NET DI differentiation using Keyed Services

Open aronDisi opened this issue 1 year ago • 1 comments

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

aronDisi avatar Aug 14 '24 19:08 aronDisi

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.

ZeeLyn avatar Aug 15 '24 04:08 ZeeLyn