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

FromKeyedServices attribute support #397

Open
vadimi-ep opened this issue Mar 29, 2024 · 2 comments
Open

FromKeyedServices attribute support #397

vadimi-ep opened this issue Mar 29, 2024 · 2 comments

Comments

@vadimi-ep
Copy link

Hello, it looks like lamar does not support FromKeyedServicesAttribute which is available in .net8:

public class TestClient
{
    public TestClient(
        [FromKeyedServices("c1")] IMyClient myClient1,
        [FromKeyedServices("c2")] IMyClient myClient2)
    {
        var res = myClient1.GetValue() == myClient2.GetValue();
    }
}

// Container initialization code
var container = new Lamar.Container(x =>
{
    x.AddKeyedSingleton<IMyClient>("c1", (p, _) => new MyClient(1));
    x.AddKeyedSingleton<IMyClient>("c2", (p, _) => new MyClient(2));
    x.AddTransient<TestClient>();
});

var s = container.GetService<TestClient>();

container.GetService<TestClient>() ignores FromKeyedServices attribute and injects the same instance of the dependency instead of the keyed one.

@jeremydmiller
Copy link
Member

@vadimi-ep Just reminding you that Lamar predates that Microsoft introduced attribute by quite a few years. This is an "I take pull requests" issue (and won't be that bad if you care).

Lamar has its own attribute for naming if that's all you need. Or use Lamar's own built in registration DSL for this that Lamar has supported for years before MS did the keyed service thing

@vadimi
Copy link

vadimi commented May 22, 2024

thanks, I'll try to work on the PR then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants