VitreousServiceCollectionExtensions class
Namespace: Vitreous
Assembly: Vitreous.dll
Extension methods for registering Vitreous in the ASP.NET Core DI container.
public static class VitreousServiceCollectionExtensionsInheritance
Section titled “Inheritance”object ← VitreousServiceCollectionExtensions
Inherited Members
Section titled “Inherited Members”object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Methods
Section titled “Methods”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)Parameters
Section titled “Parameters”services IServiceCollection
The service collection.
configure Action<VitreousOptions>?
Optional configuration callback.
Returns
Section titled “Returns”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)Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”
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.
Exceptions
Section titled “Exceptions”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)Parameters
Section titled “Parameters”services IServiceCollection
The service collection.
assemblies Assembly[]
One or more assemblies to scan for ICommandHandler, IQueryHandler,
IStreamQueryHandler, and INotificationHandler implementations.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”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)Parameters
Section titled “Parameters”services IServiceCollection
The service collection.
configure Action<VitreousOptions>?
Optional configuration callback.
assemblies Assembly[]
One or more assemblies to scan for handler implementations.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”Thrown when no assemblies are supplied. This usually means the
Vitreous.SourceGeneration package is not installed on the entry-point project.