BunnyTail.ServiceRegistration

May 30, 2026 ยท View on GitHub

PackageInfo
BunnyTail.ServiceRegistrationNuGet

What is this?

Service registration method generator.

Usage

using BunnyTail.ServiceRegistration;

using Microsoft.Extensions.DependencyInjection;

internal static class Program
{
    public static void Main()
    {
        using var provider = new ServiceCollection()
            .AddServices()
            .BuildServiceProvider();

        var service = provider.GetRequiredService<TestService>();
    }
}

internal static partial class ServiceCollectionExtensions
{
    [ServiceRegistration(Lifetime.Singleton, "Service$")]
    public static partial IServiceCollection AddServices(this IServiceCollection services);
}

internal sealed class TestService
{
}

Attribute Parameters

ParameterDescription
LifetimeService lifetime: Transient, Singleton, or Scoped
PatternRegex pattern to match class names to register
AssemblyAssembly to scan (defaults to the calling assembly)
NamespaceNamespace prefix to filter classes