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 · 0 comments
Open

Stack Overflow Using Inverse Expression With Same Type #409

c0nstexpr opened this issue Jan 14, 2025 · 0 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
{
}
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

1 participant