Snowberry.DependencyInjection.Abstractions 6.0.0

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

Snowberry.DependencyInjection.Abstractions

NuGet Version

The contracts of Snowberry.DependencyInjection: the container, registry, scope and factory interfaces, the injection attributes, ServiceDescriptor and ServiceLifetime, the exceptions the container throws, and the extension methods used to register and resolve services. It targets .NET 11, .NET 10 and .NET Standard 2.0, is annotated for trimming and Native AOT, and has no runtime dependencies.

Reference it from a library that registers or resolves services without taking a dependency on the container implementation; the application that composes everything references Snowberry.DependencyInjection, which brings this package along.

Table of Contents

Installation

dotnet add package Snowberry.DependencyInjection.Abstractions

Quick Start

using Snowberry.DependencyInjection;
using Snowberry.DependencyInjection.Abstractions.Extensions;
using Snowberry.DependencyInjection.Abstractions.Interfaces;

// 3. The application, which references Snowberry.DependencyInjection, composes and resolves.
using var container = new ServiceContainer();
container.AddGreeting();

Console.WriteLine(container.GetRequiredService<IGreeter>().Greet("world"));

// 1. A library that references only the abstractions declares its services...
public interface IGreeter { string Greet(string name); }
internal sealed class Greeter : IGreeter { public string Greet(string name) => $"Hello, {name}!"; }

// 2. ...and exposes a registration method over the IServiceRegistry contract.
public static class GreetingRegistration
{
    public static IServiceRegistry AddGreeting(this IServiceRegistry registry)
    {
        registry.RegisterSingleton<IGreeter, Greeter>();
        return registry;
    }
}

Top Features at a Glance

  • Container-agnostic registration. Write AddXyz(this IServiceRegistry registry) methods against the interfaces; any IServiceRegistry implementation can consume them.
  • Typed registration helpers. RegisterSingleton, RegisterScoped and RegisterTransient with implementation types, instances or ServiceInstanceFactory<T> factories, each optionally keyed, plus TryRegister* variants.
  • Typed resolution helpers. GetService<T>, GetRequiredService<T>, GetKeyedService<T>, GetRequiredKeyedService<T>, CreateScope and CreateInstance<T> on any IServiceProvider.
  • Injection attributes. [Inject], [FromKeyedServices] and [PreferredConstructor] mark types for the container without referencing it.
  • Explicit failures. Dedicated exceptions (ServiceTypeNotRegistered, CircularDependencyException, ServiceValidationException, ...) and a structured ServiceValidationError list from validation.
  • Trimming-safe signatures. Type parameters and Type arguments that are activated carry [DynamicallyAccessedMembers], so the trimmer keeps the constructors and properties the container needs.

What Is Inside

Export Kind Purpose
IServiceContainer Interface The full container: registry, descriptor lookup, keyed service provider and disposal.
IServiceRegistry Interface Register, UnregisterService and IsServiceRegistered.
IServiceDescriptorReceiver Interface Looks up registered IServiceDescriptors; enumerable over all of them.
IKeyedServiceProvider Interface IServiceProvider plus GetKeyedService(Type, object?).
IServiceScopeFactory / IScope Interfaces Create scopes; a scope exposes its provider, scoped-instance cache and disposables.
IServiceFactory Interface Constructs instances of implementation types; the container's activation strategy.
IDisposableContainer Interface Tracks the disposables owned by a scope or container.
IServiceDescriptor / ServiceDescriptor Interface / class A registration: service type, implementation type, lifetime, instance or factory. ServiceDescriptor.Singleton/Scoped/Transient create one.
IServiceIdentifier / IScopeServiceCacheEntry Interfaces A service type plus optional key; a cached scoped instance.
ServiceInstanceFactory / ServiceInstanceFactory<T> Delegates Factories that receive the resolving provider and the service key.
ServiceLifetime Enum Singleton, Scoped, Transient.
InjectAttribute, FromKeyedServicesAttribute, PreferredConstructorAttribute Attributes Property injection, keyed dependency selection, constructor selection.
ServiceTypeNotRegistered, CircularDependencyException, ServiceRegistryReadOnlyException, ServiceScopeRequiredException, InvalidServiceImplementationType, ServiceValidationException Exceptions The failures the container reports.
ServiceValidationError / ServiceValidationErrorKind Class / enum One validation problem: MissingDependency, CircularDependency or NoPublicConstructor.
ServiceRegistryExtensions, ServiceProviderExtensions Static classes The registration and resolution helpers below.
ThrowHelper Static class Throw helpers for IServiceFactory implementations.

Extension Methods

Registration, on IServiceRegistry (namespace Snowberry.DependencyInjection.Abstractions.Extensions):

Method Registers
RegisterSingleton<T>(), RegisterSingleton<T, TImpl>() A singleton constructed by the container.
RegisterSingleton<T>(T instance), RegisterSingleton<T, TImpl>(TImpl instance) A pre-built singleton instance (not disposed by the container).
RegisterSingleton<T>(ServiceInstanceFactory<T>), RegisterSingleton<T, TImpl>(ServiceInstanceFactory<TImpl>) A singleton created by a factory.
RegisterScoped<...>(...), RegisterTransient<...>(...) The same type and factory forms for the other lifetimes.
TryRegister(descriptor), TryRegisterSingleton/Scoped/Transient<...>(...) Like the above, but returns false instead of registering when the service is already registered.

Every registration method takes an optional serviceKey.

Resolution, on IServiceProvider / IKeyedServiceProvider:

Method Returns
GetService<T>(), GetKeyedService<T>(key) The service, or default when it is not registered.
GetRequiredService<T>(), GetRequiredService(Type) The service; throws ServiceTypeNotRegistered when it is not registered.
GetRequiredKeyedService<T>(key), GetRequiredKeyedService(Type, key) The keyed service; throws ServiceTypeNotRegistered when it is not registered.
CreateScope() A new IScope from the provider's IServiceScopeFactory.
CreateInstance<T>(), CreateInstance(Type) A new instance of an unregistered type, with its dependencies injected.

Pitfalls

  • The abstractions do not contain a container. ServiceContainer and ServiceContainerOptions live in Snowberry.DependencyInjection; reference that package in the application that composes the services.
  • A wrong implementation type fails at resolve time. GetService<T> and the other typed helpers throw InvalidCastException when the registered instance is not a T.
  • CreateInstance is not trimming or AOT safe. It is annotated [RequiresUnreferencedCode] and [RequiresDynamicCode] because it can close generic types at runtime; prefer registering the type.
  • Async disposal is .NET only. On .NET Standard 2.0 the interfaces do not include IAsyncDisposable and RegisterDisposable(IAsyncDisposable).
Package Purpose
Snowberry.DependencyInjection The container that implements these contracts.
Snowberry.Mediator.DependencyInjection Registers Snowberry.Mediator handlers in the Snowberry container.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 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.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Snowberry.DependencyInjection.Abstractions:

Package Downloads
Snowberry.DependencyInjection

A lightweight easy to use IoC container for .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 221 11/12/2026
5.2.0 1,661 5/31/2026
5.1.1 1,996 1/28/2026
5.1.0 731 11/15/2025
5.0.0.2 484 11/4/2025
5.0.0.1 385 11/4/2025 5.0.0.1 is deprecated because it is no longer maintained.
5.0.0 392 11/4/2025 5.0.0 is deprecated because it is no longer maintained.
4.0.0 314 10/7/2025