NCode.Registration 0.1.1

Prefix Reserved
dotnet add package NCode.Registration --version 0.1.1
                    
NuGet\Install-Package NCode.Registration -Version 0.1.1
                    
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="NCode.Registration" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NCode.Registration" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="NCode.Registration" />
                    
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 NCode.Registration --version 0.1.1
                    
#r "nuget: NCode.Registration, 0.1.1"
                    
#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 NCode.Registration@0.1.1
                    
#: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=NCode.Registration&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=NCode.Registration&version=0.1.1
                    
Install as a Cake Tool

NCode.Registration

CI Target framework Documentation License

Dependency injection registration for .NET that proves each library's prerequisites at compile time: every Add…Library() returns a marker builder, IServiceBuilder<TMarker>, that the libraries it needs extend, so a registration whose prerequisite is missing doesn't compile. BindStrictly binds a configuration section so that a key no property takes stops the host instead of being ignored.

Installation

dotnet add package NCode.Registration

The package depends on Microsoft.Extensions.DependencyInjection.Abstractions and Microsoft.Extensions.Configuration.Binder.

Example

Each library declares a marker, an empty readonly struct, and its Add…Library() returns the builder for that marker. A library with no prerequisite extends IServiceCollection; a library that needs another extends that library's builder:

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NCode.Registration;

public readonly struct ClockLibrary : IRegistrationMarker<ClockLibrary>;

public readonly struct GreetingLibrary : IRegistrationMarker<GreetingLibrary>;

public sealed class GreetingOptions
{
    public string Greeting { get; set; } = "Hello";
}

public static class ClockLibraryRegistration
{
    extension(IServiceCollection services)
    {
        public IServiceBuilder<ClockLibrary> AddClockLibrary()
        {
            services.TryAddSingleton(TimeProvider.System);
            return services.NewBuilder<ClockLibrary>();
        }
    }
}

public static class GreetingLibraryRegistration
{
    extension(IServiceBuilder<ClockLibrary> builder)
    {
        public IServiceBuilder<GreetingLibrary> AddGreetingLibrary(IConfigurationSection section)
        {
            builder
                .ServiceCollection.AddOptions<GreetingOptions>()
                .Configure(options => section.BindStrictly(options))
                .ValidateOnStart();
            return builder.NewBuilder<GreetingLibrary>();
        }
    }
}

A host registers the libraries in order, and services.AddGreetingLibrary(…) without AddClockLibrary() before it doesn't compile:

services.AddClockLibrary().AddGreetingLibrary(configuration.GetSection("Greeting"));

Registering a library's marker twice throws InvalidOperationException, and a Greeting section with a key such as Greting that GreetingOptions has no property for stops the host as it starts.

The repository's readme shows how to require a second library, share one marker among several registrations, register several instances of one service and bind configuration strictly.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
0.1.1 0 12/6/2026
0.1.0 0 12/5/2026