You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
{
}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: