Registrator.Net 3.1.0

dotnet add package Registrator.Net --version 3.1.0
                    
NuGet\Install-Package Registrator.Net -Version 3.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Registrator.Net" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Registrator.Net" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Registrator.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Registrator.Net --version 3.1.0
                    
#r "nuget: Registrator.Net, 3.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Registrator.Net@3.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Registrator.Net&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Registrator.Net&version=3.1.0
                    
Install as a Cake Tool

N|Solid

Registrator.Net

A simple yet effective auto registration tool for dotnet

NuGet Info GitHub License CI

Table of contents

Notes

Doesn't support automatic registration of generic types, you will have to register them manually.

About

Registrator.Net is a simple auto registration tool for dotnet.

I have been trying to find a simple tool to register my internal dependencies and didn't find any that I liked, so I decided to create my own.

Who is it for?

Registrator.Net is intended for developers who want something simple that just works.

It is not designed to deal with every case, but the simple ones, the ones you will be doing 99% of the time.

Getting Started

Installation

Install-Package Registrator.Net

Tag classes, records and structs with any of the following attributes:

  • AutoRegisterType
  • AutoRegisterTypeAndInterfaces
  • AutoRegisterInterfaces

Then in your Program.cs or Startup.cs, call services.AutoRegisterTypesInAssemblies(assembly1,assembly2,assembly3...);

If you want to skip the registration of types that implement a certain interface from a certain assembly, you can call

services.AutoRegisterTypesInAssemblies(new RegistratorConfiguration()
{
    Assemblies = [typeof(ConcreteType).Assembly],
    ExcludedAssemblies = [typeof(IRequestHandler<>).Assembly,typeof(IMediator).Assembly]
});

By default all registered types are registered as ServiceLifetime.Scoped, but you can change it by passing a ServiceLifetime as a parameter of the attribute. You can also add keyed services if you use the Key property of the attribute.

[AutoRegisterInterfaces(ServiceLifetime.Scoped, "17")]
public class ConcreteType17 : IInterface25, IInterface26 { }

In the above the interfaces of the class with be resolved to ConcreteType17 when requested with the key 17

Advanced Usage

Tagging

You can tag your types with the tag property of the attributes. If a tag is provided, the type will be registered only if the tag is null or present in the RegistratorConfiguration.Tags array or if the tag is null.

Example

[AutoRegisterTypeAndInterfaces(ServiceLifetime.Transient, tag: "tag1")]
public class ConcreteTypeWithMatchingTags : IInterfaceAndTypeWithMatchingTags { }

[AutoRegisterTypeAndInterfaces(ServiceLifetime.Transient, tag: "tag2")]
public class ConcreteTypeWithNoMatchingTags : IInterfaceAndTypeWithNoMatchingTags { }

[AutoRegisterTypeAndInterfaces(ServiceLifetime.Transient)]
public class ConcreteTypeWithNoTags : IInterfaceAndTypeWithNoTags { }

...
    
    services.AutoRegisterTypesInAssemblies(c =>
    {
        c.Assemblies = [typeof(ConcreteType).Assembly];
        c.Tags = ["tag1"];
    });

In the above example, only ConcreteTypeWithMatchingTags and ConcreteTypeWithNoTags will be registered.

Excluding types from registration by namespace

You can exclude types from registration by namespace by using the ExcludedTypesNamespaces property of the RegistratorConfiguration class. The decision to use Types to discover the namespace was made to avoid the use of strings and make it more type safe. Example:

services.AutoRegisterTypesInAssemblies(c =>
{
    c.Assemblies = [typeof(ConcreteType).Assembly];
    c.ExcludedTypesNamespaces = [typeof(ClassToExclude)];
});

In the above example, all types sharing the namespace of ClassToExclude will be excluded from registration.

License

MIT

Logo Provided by Vecteezy

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 292 6/29/2025
3.0.0 7,663 9/21/2024
2.0.0 637 9/1/2024
1.1.1 2,761 4/7/2024
1.1.0 128 4/7/2024
1.0.0 158 4/6/2024

Added support for tags, Allowed to exclude types by namespace