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

Stack Overflow Using Inverse Expression With Same Type #409

Open
c0nstexpr opened this issue Jan 14, 2025 · 2 comments
Open

Stack Overflow Using Inverse Expression With Same Type #409

c0nstexpr opened this issue Jan 14, 2025 · 2 comments

Comments

@c0nstexpr
Copy link

using Lamar;
using Lamar.Microsoft.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder()
    .UseLamar(
        registry =>
        {
            registry.AddSingleton<A>();
            registry.Use<B>().Singleton().For<IB>();
            registry.For<C>().Use<C>().Singleton();
            registry.Use<D>().Singleton().For<D>();
        }
    );

var host = builder.Build();

host.Start();

var services = host.Services;

Console.WriteLine(ReferenceEquals(services.GetRequiredService<A>(), services.GetRequiredService<A>()));

Console.WriteLine(ReferenceEquals(services.GetRequiredService<B>(), services.GetRequiredService<B>()));

Console.WriteLine(ReferenceEquals(services.GetRequiredService<C>(), services.GetRequiredService<C>()));

Console.WriteLine(ReferenceEquals(services.GetRequiredService<D>(), services.GetRequiredService<D>())); // StackOverflow

class A
{
}

interface IB
{
}

class B : IB
{
}

class C
{
}

class D
{
}
@jeremydmiller
Copy link
Member

@c0nstexpr I think the most likely action here is that the "inverse" expression stuff is ripped out in the next version. It's been buggy in the past. I took that in from a PR , and the original author of that is no longer involved.

@c0nstexpr
Copy link
Author

@c0nstexpr I think the most likely action here is that the "inverse" expression stuff is ripped out in the next version. It's been buggy in the past. I took that in from a PR , and the original author of that is no longer involved.

I agree, user like me would found such feature is confusing

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

2 participants