Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Keyed Services in Minimal APIs #49633

Closed
adityamandaleeka opened this issue Jul 26, 2023 · 1 comment
Closed

Support Keyed Services in Minimal APIs #49633

adityamandaleeka opened this issue Jul 26, 2023 · 1 comment
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdf feature-rdg
Milestone

Comments

@adityamandaleeka
Copy link
Member

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();
    }
}
@BrennanConroy
Copy link
Member

Done via #50095

@dotnet dotnet locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdf feature-rdg
Projects
None yet
Development

No branches or pull requests

4 participants