lamar icon indicating copy to clipboard operation
lamar copied to clipboard

Stack Overflow Using Inverse Expression With Same Type

Open c0nstexpr opened this issue 1 year ago • 2 comments

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
{
}

c0nstexpr avatar Jan 14 '25 13:01 c0nstexpr

@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.

jeremydmiller avatar Feb 05 '25 19:02 jeremydmiller

@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

c0nstexpr avatar Feb 06 '25 06:02 c0nstexpr