Skip to content

IServiceCollectionPlugin

NexusLabs.Needlr

NexusLabs.Needlr

IServiceCollectionPlugin Interface

Defines a plugin that participates in Needlr's Microsoft.Extensions.DependencyInjection.IServiceCollection configuration pipeline. Implement this interface to encapsulate a cohesive block of service registrations that can be discovered and applied automatically during startup.

public interface IServiceCollectionPlugin

Example

public class InfrastructurePlugin : IServiceCollectionPlugin
{
    public void Configure(ServiceCollectionPluginOptions options)
    {
        options.Services.AddSingleton<IConnectionFactory, SqlConnectionFactory>();
        options.Services.AddScoped<IUnitOfWork, SqlUnitOfWork>();
    }
}

Remarks

Plugins are discovered and invoked by the Needlr startup pipeline as part of its fluent setup chain. The DoNotAutoRegisterAttribute and DoNotInjectAttribute on this interface prevent Needlr from mistakenly registering it as a concrete service.

Create a class that implements IServiceCollectionPlugin and place your registration logic in Configure(ServiceCollectionPluginOptions). Needlr will call Configure(ServiceCollectionPluginOptions) once during the startup assembly scan.

Do not apply DoNotAutoRegisterAttribute directly to an implementing class. This interface already carries the attribute to prevent DI registration of the interface itself; adding it to the class too is redundant and was historically a silent bug that suppressed plugin discovery. Analyzer NDLRCOR016 will warn you if you do this.

Methods

IServiceCollectionPlugin.Configure(ServiceCollectionPluginOptions) Method

Configures the Microsoft.Extensions.DependencyInjection.IServiceCollection instance.

void Configure(NexusLabs.Needlr.ServiceCollectionPluginOptions options);

Parameters

options ServiceCollectionPluginOptions