Skip to content

Auto registration with multiple lifetimes

The following example shows auto registration failing due to a class having multiple lifetimes:

new ServiceCollection()
    .AutoRegisterServicesFromAssemblyOf<Program>();

The dependent interfaces and classes are defined as follows:

public interface IMyClass
{
    void SayHello(string name);
}

public class MyClass : IMyClass, IScopedService, ISingletonService
{
    public void SayHello(string name) => Console.WriteLine($"Hello {name}");
}