SharedKernel exposes clean, composableDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/jordiaragonzaragoza/JordiAragonZaragoza.SharedKernel/llms.txt
Use this file to discover all available pages before exploring further.
IServiceCollection extension methods organized by architectural concern. Rather than one monolithic registration call, you opt into each subsystem — core infrastructure services, the command bus, the query bus, and projections — independently. This keeps your composition root explicit and makes it straightforward to replace or extend individual pieces without disturbing others.
Extension Methods Overview
AddSharedKernelInfrastructure
Registers core singletons:
IDateTime, IIdGenerator, IPartitionContextService, IUserContextService, ICacheService, and IIdentityService.AddSharedKernelInfrastructureCommandBus
Registers the MediatR command pipeline with all behaviors and binds
ICommandBus to CommandBus.AddSharedKernelInfrastructureQueryBus
Registers the MediatR query pipeline with all behaviors and binds
IQueryBus to QueryBus.AddSharedKernelInfrastructureProjections
Registers the projection event bus pipeline and binds
IEventBus to InMemoryEventBus.Infrastructure Layer Registration
AddSharedKernelInfrastructure
Registers the foundational cross-cutting services needed by all application code.
| Interface | Implementation | Lifetime | Purpose |
|---|---|---|---|
IDateTime | DateTimeService | Singleton | Abstracts DateTimeOffset.UtcNow for testability |
IIdGenerator | IdGeneratorService | Singleton | Generates UUIDv7 identifiers via Guid.CreateVersion7() |
IPartitionContextService | PartitionContextService | Singleton | Holds the current tenantId / partitionId in AsyncLocal storage |
IUserContextService | UserContextService | Singleton | Holds the current userId in AsyncLocal storage |
ICacheService | CacheService | Transient | Provides get/set/remove-by-prefix caching abstraction |
IIdentityService | IdentityService | Transient | Provides identity/authorization helpers |
IPartitionContextService and IUserContextService
Both services store their context in AsyncLocal<T> fields, so each async flow (e.g., each HTTP request) has its own isolated context without risk of data leaking across concurrent requests.
AddSharedKernelInfrastructureCommandBus
Wires up the MediatR command pipeline and registers ICommandBus.
CommandBus delegates to MediatR’s ISender:
AddSharedKernelInfrastructureQueryBus
Wires up the MediatR query pipeline and registers IQueryBus.
QueryBus delegates to MediatR’s ISender:
AddSharedKernelInfrastructureProjections
Registers the in-process event publication pipeline used by projections.
InMemoryEventBus wraps MediatR’s IPublisher to fan out domain events to all registered INotificationHandler projections:
Application Layer Registration
The Application layer registers the pipeline service objects that the MediatR behaviors delegate to. These must be registered alongside the infrastructure bus registrations.AddSharedKernelApplicationCommandBus
AddSharedKernelApplicationQueryBus
Identical to the command variant except IRequestUnitOfWorkService is omitted — queries are read-only and do not require a transactional unit of work.
MediatR Pipeline Behaviors
The command bus pipeline runs behaviors in the following order. Each behavior in the chain calls
next() to pass control to the subsequent behavior and ultimately to your handler:LoggerBehaviour<TRequest>(pre-processor) — logs the incoming request before the pipeline runs.ExceptionHandlerPipelineBehaviour<TRequest, TResponse>— wraps the pipeline in a try/catch and converts exceptions toResulterrors.UnitOfWorkBehaviour<TRequest, TResponse>— begins a database transaction for commands that implementITransactionalCommand, commits on success, rolls back on failure.AuthorizationBehaviour<TRequest, TResponse>— evaluates authorization rules; short-circuits with aForbiddenresult when the caller is not authorized.ValidationBehaviour<TRequest, TResponse>— runs FluentValidation validators; short-circuits with anInvalidresult on failure.CachingBehavior<TRequest, TResponse>— checks the cache for requests implementingICacheRequest; returns cached value or populates it after the handler runs.InvalidateCachingBehavior<TRequest, TResponse>— evicts cache entries by prefix for requests implementingIInvalidateCacheRequest.PerformancePipelineBehaviour<TRequest, TResponse>— tracks and logs slow-running requests.
UnitOfWorkBehaviour (step 3).