Why it matters
Runtime activation fails when DI tries to create the service.
Planning to build a kite without string means the build fails when you start.
DI015
Registered services with direct or transitive constructor/factory dependencies that are not registered (including keyed and open-generic paths). Type parameters and closed generics containing them are not reported as missing, because the closed type is unknown. A non-generic DbContextOptions dependency is satisfied by any registered DbContextOptions<TContext>.
Why it matters
Runtime activation fails when DI tries to create the service.
Planning to build a kite without string means the build fails when you start.
Install
dotnet add package DependencyInjection.Lifetime.Analyzers --version 3.10.1
README problem example
public interface IMissingDependency { }
public interface IMyService { }
public sealed class MyService : IMyService
{
public MyService(IMissingDependency missing) { }
}
services.AddSingleton<IMyService, MyService>();
README better pattern
public sealed class MissingDependency : IMissingDependency { }
services.AddScoped<IMissingDependency, MissingDependency>();
services.AddSingleton<IMyService, MyService>();
Repo sample extraction
Sample app warning case
public class BadUnresolvableService
{
public BadUnresolvableService(IMissingDependency missing) { }
}
Sample app safe pattern
public class GoodResolvableService
{
public GoodResolvableService(IRegisteredDependency dependency) { }
}
Related guides
More documentation
Nearby diagnostics
DI014
DI016
DI017