Skip to content

Manual Registrator Customization

Alexander Stärk edited this page Sep 25, 2026 · 1 revision

Extending the Generated Registrator

Terminology note

This page is about manual customization of the generated DependencyRegistrator partial class inside a consumer project.

It is not the same concept as analyzer extension support for other source generators.

For analyzer extension support, see Analyzer Extension Support (for Source Generators).

The generated DependencyRegistrator is partial and intentionally extensible.

Why extend it?

Use custom partial method implementations when:

  • you need registrations that are hard to express with attributes
  • you need pre/post logic around generated registration
  • you want to integrate registrations from other tools

Example

using Microsoft.Extensions.DependencyInjection;

public partial class DependencyRegistrator
{
    partial void doAfterRegistration(IServiceCollection services)
    {
        services.AddSingleton<IMyManualService, MyManualService>();
    }
}

You can implement any generated partial hook methods your scenario requires.

Keep responsibilities clear

Recommended split:

  • Attribute registrations: default path for most services
  • Partial extension code: exceptional or advanced scenarios

This keeps generated and manual registration logic easy to maintain.

Clone this wiki locally