Class CaesarServiceConfiguration
- Namespace
- Caesar.DependencyInjection
- Assembly
- Caesar.dll
Options for AddCaesar: which assemblies to scan, which behaviors to add, and how services are registered.
public sealed class CaesarServiceConfiguration
- Inheritance
-
CaesarServiceConfiguration
- Inherited Members
Constructors
CaesarServiceConfiguration()
public CaesarServiceConfiguration()
Properties
AssembliesToRegister
Assemblies that will be scanned for handlers.
public IReadOnlyList<Assembly> AssembliesToRegister { get; }
Property Value
AutoRegisterRequestProcessors
When true (default) scanned IRequestPreProcessor<TRequest> and
IRequestPostProcessor<TRequest, TResponse> implementations are registered automatically.
Set to false to register processors only explicitly via AddRequestPreProcessor / AddRequestPostProcessor.
public bool AutoRegisterRequestProcessors { get; set; }
Property Value
BypassExceptionHandlingOnCallerCancellation
When true, an OperationCanceledException thrown while the caller's cancellation token
is cancelled propagates without reaching exception handlers or exception actions, so a catch-all handler cannot
turn an aborted request into a fallback response. Cancellation from any other token, such as a timeout a behavior
adds, is still routed. Default: false: cancellations reach handlers and actions like any other
exception, as in MediatR, and each handler receives the token to tell them apart itself.
A global option: when AddCaesar is called more than once, a later call may not set a different value.
public bool BypassExceptionHandlingOnCallerCancellation { get; set; }
Property Value
Lifetime
Lifetime for every scanned handler, processor, exception handler and exception action. Default:
Transient. A processor also added with AddRequestPreProcessor or
AddRequestPostProcessor keeps the lifetime given there.
public ServiceLifetime Lifetime { get; set; }
Property Value
MediatorImplementationType
The IMediator implementation to register. Default: Mediator.
A global option: when AddCaesar is called more than once, a later call may not set a different value.
public Type MediatorImplementationType { get; set; }
Property Value
MediatorLifetime
Lifetime for IMediator, ISender, IPublisher and
INotificationPublisher. Default: Scoped, so that a singleton
capturing the mediator is reported by container validation at startup instead of failing on the first request.
Set to Transient when the mediator must be resolvable straight from the root
provider, for example in a short console application with no scoped dependencies.
A global option: when AddCaesar is called more than once, a later call may not set a different value.
public ServiceLifetime MediatorLifetime { get; set; }
Property Value
Remarks
Avoid Singleton in an application that uses scopes, such as a web application. A
singleton mediator resolves every handler and its dependencies from the root provider, even when
ISender is injected inside a scope: scoped services such as a DbContext or the current user
are then shared by every request and every user, and disposable transient handlers are kept by the root provider
until the application shuts down. A singleton that needs to send requests should inject
IServiceScopeFactory and resolve ISender from a scope it creates.
NotificationPublisher
A ready-made publisher instance. Takes precedence over NotificationPublisherType when set.
A global option: when AddCaesar is called more than once, a later call may not set a different value.
public INotificationPublisher? NotificationPublisher { get; set; }
Property Value
NotificationPublisherType
The publisher type to register. Default: ForeachAwaitPublisher.
A global option: when AddCaesar is called more than once, a later call may not set a different value.
public Type NotificationPublisherType { get; set; }
Property Value
RequestExceptionActionProcessorStrategy
Where exception actions sit in the pipeline. Default: ApplyForUnhandledExceptions.
A global option: when AddCaesar is called more than once, a later call may not set a different value.
public RequestExceptionActionProcessorStrategy RequestExceptionActionProcessorStrategy { get; set; }
Property Value
TypeEvaluator
Filters the types found while scanning. Return false to skip a type. Default: accept everything.
public Func<Type, bool> TypeEvaluator { get; set; }
Property Value
Methods
AddBehavior(Type, ServiceLifetime)
Adds a closed behavior. The service type is every IPipelineBehavior<TRequest, TResponse> it implements.
public CaesarServiceConfiguration AddBehavior(Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
implementationTypeTypelifetimeServiceLifetime
Returns
AddBehavior(Type, Type, ServiceLifetime)
Adds a closed behavior for one specific service type.
public CaesarServiceConfiguration AddBehavior(Type serviceType, Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
serviceTypeTypeimplementationTypeTypelifetimeServiceLifetime
Returns
AddBehavior<TImplementation>(ServiceLifetime)
Adds a closed behavior. The service type is every IPipelineBehavior<TRequest, TResponse> it implements.
public CaesarServiceConfiguration AddBehavior<TImplementation>(ServiceLifetime lifetime = ServiceLifetime.Transient) where TImplementation : class
Parameters
lifetimeServiceLifetime
Returns
Type Parameters
TImplementation
AddBehavior<TService, TImplementation>(ServiceLifetime)
Adds a closed behavior for one specific service type.
public CaesarServiceConfiguration AddBehavior<TService, TImplementation>(ServiceLifetime lifetime = ServiceLifetime.Transient) where TService : class where TImplementation : class, TService
Parameters
lifetimeServiceLifetime
Returns
Type Parameters
TServiceTImplementation
AddOpenBehavior(Type, ServiceLifetime)
Adds an open-generic behavior such as typeof(LoggingBehavior<,>) that applies to every request.
The type must implement IPipelineBehavior<TRequest, TResponse> with its own two type parameters.
public CaesarServiceConfiguration AddOpenBehavior(Type openBehaviorType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
openBehaviorTypeTypelifetimeServiceLifetime
Returns
AddOpenBehaviors(IEnumerable<Type>, ServiceLifetime)
Adds several open-generic behaviors.
public CaesarServiceConfiguration AddOpenBehaviors(IEnumerable<Type> openBehaviorTypes, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
openBehaviorTypesIEnumerable<Type>lifetimeServiceLifetime
Returns
AddOpenRequestPostProcessor(Type, ServiceLifetime)
Adds an open-generic post-processor that applies to every request.
public CaesarServiceConfiguration AddOpenRequestPostProcessor(Type openProcessorType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
openProcessorTypeTypelifetimeServiceLifetime
Returns
AddOpenRequestPreProcessor(Type, ServiceLifetime)
Adds an open-generic pre-processor that applies to every request.
public CaesarServiceConfiguration AddOpenRequestPreProcessor(Type openProcessorType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
openProcessorTypeTypelifetimeServiceLifetime
Returns
AddOpenStreamBehavior(Type, ServiceLifetime)
Adds an open-generic stream behavior that applies to every stream request.
public CaesarServiceConfiguration AddOpenStreamBehavior(Type openBehaviorType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
openBehaviorTypeTypelifetimeServiceLifetime
Returns
AddRequestPostProcessor(Type, ServiceLifetime)
Adds a closed post-processor.
public CaesarServiceConfiguration AddRequestPostProcessor(Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
implementationTypeTypelifetimeServiceLifetime
Returns
AddRequestPostProcessor(Type, Type, ServiceLifetime)
Adds a closed post-processor for one specific service type.
public CaesarServiceConfiguration AddRequestPostProcessor(Type serviceType, Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
serviceTypeTypeimplementationTypeTypelifetimeServiceLifetime
Returns
AddRequestPostProcessor<TImplementation>(ServiceLifetime)
Adds a closed post-processor.
public CaesarServiceConfiguration AddRequestPostProcessor<TImplementation>(ServiceLifetime lifetime = ServiceLifetime.Transient) where TImplementation : class
Parameters
lifetimeServiceLifetime
Returns
Type Parameters
TImplementation
AddRequestPreProcessor(Type, ServiceLifetime)
Adds a closed pre-processor.
public CaesarServiceConfiguration AddRequestPreProcessor(Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
implementationTypeTypelifetimeServiceLifetime
Returns
AddRequestPreProcessor(Type, Type, ServiceLifetime)
Adds a closed pre-processor for one specific service type.
public CaesarServiceConfiguration AddRequestPreProcessor(Type serviceType, Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
serviceTypeTypeimplementationTypeTypelifetimeServiceLifetime
Returns
AddRequestPreProcessor<TImplementation>(ServiceLifetime)
Adds a closed pre-processor.
public CaesarServiceConfiguration AddRequestPreProcessor<TImplementation>(ServiceLifetime lifetime = ServiceLifetime.Transient) where TImplementation : class
Parameters
lifetimeServiceLifetime
Returns
Type Parameters
TImplementation
AddStreamBehavior(Type, ServiceLifetime)
Adds a closed stream behavior.
public CaesarServiceConfiguration AddStreamBehavior(Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
implementationTypeTypelifetimeServiceLifetime
Returns
AddStreamBehavior(Type, Type, ServiceLifetime)
Adds a closed stream behavior for one specific service type.
public CaesarServiceConfiguration AddStreamBehavior(Type serviceType, Type implementationType, ServiceLifetime lifetime = ServiceLifetime.Transient)
Parameters
serviceTypeTypeimplementationTypeTypelifetimeServiceLifetime
Returns
AddStreamBehavior<TImplementation>(ServiceLifetime)
Adds a closed stream behavior.
public CaesarServiceConfiguration AddStreamBehavior<TImplementation>(ServiceLifetime lifetime = ServiceLifetime.Transient) where TImplementation : class
Parameters
lifetimeServiceLifetime
Returns
Type Parameters
TImplementation
RegisterServicesFromAssemblies(params IEnumerable<Assembly>)
Adds several assemblies to the scan list.
public CaesarServiceConfiguration RegisterServicesFromAssemblies(params IEnumerable<Assembly> assemblies)
Parameters
assembliesIEnumerable<Assembly>
Returns
RegisterServicesFromAssembly(Assembly)
Adds assembly to the scan list.
public CaesarServiceConfiguration RegisterServicesFromAssembly(Assembly assembly)
Parameters
assemblyAssembly
Returns
RegisterServicesFromAssemblyContaining(Type)
Adds the assembly that contains type to the scan list.
public CaesarServiceConfiguration RegisterServicesFromAssemblyContaining(Type type)
Parameters
typeType
Returns
RegisterServicesFromAssemblyContaining<T>()
Adds the assembly that contains T to the scan list.
public CaesarServiceConfiguration RegisterServicesFromAssemblyContaining<T>()
Returns
Type Parameters
T