Skip to content

VitreousServiceCollectionExtensions class

Namespace: Vitreous
Assembly: Vitreous.dll

Extension methods for registering Vitreous in the ASP.NET Core DI container.

public static class VitreousServiceCollectionExtensions

object ← VitreousServiceCollectionExtensions

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

AddVitreous(IServiceCollection, Action<VitreousOptions>?)

Section titled “ AddVitreous(IServiceCollection, Action<VitreousOptions>?)”

Registers Vitreous core services (sender, publisher).

When the Vitreous.SourceGeneration package is referenced, it generates a concrete AddVitreousHandlers() call and a VitreousDispatcher that replace the reflection-based fallbacks registered here.

[RequiresUnreferencedCode("Vitreous dispatches with reflection when it is registered this way. For trimmed or Native AOT apps, install Vitreous.SourceGeneration and call the generated AddVitreousHandlers() overload with no assemblies.")]
[RequiresDynamicCode("Vitreous dispatches with reflection when it is registered this way. For trimmed or Native AOT apps, install Vitreous.SourceGeneration and call the generated AddVitreousHandlers() overload with no assemblies.")]
public static IServiceCollection AddVitreous(this IServiceCollection services, Action<VitreousOptions>? configure = null)

services IServiceCollection

The service collection.

configure Action<VitreousOptions>?

Optional configuration callback.

IServiceCollection

AddVitreousBehavior(IServiceCollection, Type, ServiceLifetime)

Section titled “ AddVitreousBehavior(IServiceCollection, Type, ServiceLifetime)”

Registers a pipeline behavior for every message: an open generic such as typeof(LoggingBehavior<,>), or a closed behavior for one message type. Adding the same behavior again does nothing.

public static IServiceCollection AddVitreousBehavior(this IServiceCollection services, Type behaviorType, ServiceLifetime lifetime = ServiceLifetime.Transient)

services IServiceCollection

The service collection.

behaviorType Type

A type implementing IPipelineBehavior<TMessage, TResult>, IStreamPipelineBehavior<TMessage, TResult> or INotificationPipelineBehavior<TNotification>. An open generic must pass its type parameters to the interface in order, e.g. Behavior<TMessage, TResult> : IPipelineBehavior<TMessage, TResult>.

lifetime ServiceLifetime

The behavior’s lifetime. Default: transient.

IServiceCollection

Behaviors run in registration order, outermost first, together with behaviors registered directly as IPipelineBehavior<,> services.

With Vitreous.SourceGeneration, an open-generic behavior is registered closed over every message the generator found, so it also works under Native AOT for void commands, value-type results and struct messages. Registering it as an open-generic IPipelineBehavior<,> service directly fails under Native AOT for those messages.

ArgumentException

behaviorType is not a Vitreous pipeline behavior.

AddVitreousHandlers(IServiceCollection, params Assembly[])

Section titled “ AddVitreousHandlers(IServiceCollection, params Assembly[])”

Registers Vitreous core services and scans the provided assemblies for handler implementations at startup.

Use this overload in multi-project solutions when you cannot or do not want to use the Vitreous.SourceGeneration package. Handlers are discovered via reflection and dispatched through ReflectionSender at runtime.

For zero-reflection, AOT-compatible dispatch install Vitreous.SourceGeneration on the entry-point project and call the parameterless AddVitreousHandlers() overload instead.

[RequiresUnreferencedCode("Vitreous dispatches with reflection when it is registered this way. For trimmed or Native AOT apps, install Vitreous.SourceGeneration and call the generated AddVitreousHandlers() overload with no assemblies.")]
[RequiresDynamicCode("Vitreous dispatches with reflection when it is registered this way. For trimmed or Native AOT apps, install Vitreous.SourceGeneration and call the generated AddVitreousHandlers() overload with no assemblies.")]
public static IServiceCollection AddVitreousHandlers(this IServiceCollection services, params Assembly[] assemblies)

services IServiceCollection

The service collection.

assemblies Assembly[]

One or more assemblies to scan for ICommandHandler, IQueryHandler, IStreamQueryHandler, and INotificationHandler implementations.

IServiceCollection

InvalidOperationException

Thrown when no assemblies are supplied. This usually means the Vitreous.SourceGeneration package is not installed on the entry-point project.

AddVitreousHandlers(IServiceCollection, Action<VitreousOptions>?, params Assembly[])

Section titled “ AddVitreousHandlers(IServiceCollection, Action<VitreousOptions>?, params Assembly[])”

Registers Vitreous core services, applies configure, and scans the provided assemblies for handler implementations at startup.

[RequiresUnreferencedCode("Vitreous dispatches with reflection when it is registered this way. For trimmed or Native AOT apps, install Vitreous.SourceGeneration and call the generated AddVitreousHandlers() overload with no assemblies.")]
[RequiresDynamicCode("Vitreous dispatches with reflection when it is registered this way. For trimmed or Native AOT apps, install Vitreous.SourceGeneration and call the generated AddVitreousHandlers() overload with no assemblies.")]
public static IServiceCollection AddVitreousHandlers(this IServiceCollection services, Action<VitreousOptions>? configure, params Assembly[] assemblies)

services IServiceCollection

The service collection.

configure Action<VitreousOptions>?

Optional configuration callback.

assemblies Assembly[]

One or more assemblies to scan for handler implementations.

IServiceCollection

InvalidOperationException

Thrown when no assemblies are supplied. This usually means the Vitreous.SourceGeneration package is not installed on the entry-point project.