Closed
Description
Keyed services support went into M.E.DI in Preview 7. We should support it in minimal APIs, to make things like the following work:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKeyedSingleton<ICache, BigCache>("big");
builder.Services.AddKeyedSingleton<ICache, SmallCache>("small");
var app = builder.Build();
app.MapGet("/big", ([FromKeyedServices("big")] ICache cache) =>
{
return cache.Get("data");
});
app.MapGet("/small", ([FromKeyedServices("small")] ICache cache) =>
{
return cache.Get("data");
});
app.Run();
interface ICache
{
object Get(string key);
}
class BigCache : ICache
{
public object Get(string key)
{
throw new NotImplementedException();
}
}
class SmallCache : ICache
{
public object Get(string key)
{
throw new NotImplementedException();
}
}