Lewee.Application
0.40.3
dotnet add package Lewee.Application --version 0.40.3
NuGet\Install-Package Lewee.Application -Version 0.40.3
<PackageReference Include="Lewee.Application" Version="0.40.3" />
<PackageVersion Include="Lewee.Application" Version="0.40.3" />
<PackageReference Include="Lewee.Application" />
paket add Lewee.Application --version 0.40.3
#r "nuget: Lewee.Application, 0.40.3"
#:package Lewee.Application@0.40.3
#addin nuget:?package=Lewee.Application&version=0.40.3
#tool nuget:?package=Lewee.Application&version=0.40.3
Lewee.Application
This package assists with building the application layer of an application using domain-driven design principles.
Dependencies
Configuration
To use this packages add the following lines to your service configuration of your application (services in the code below is Microsoft.Extensions.DependencyInjection.ServicesCollection).
services.AddApplication(typeof(ApplicationLayerClass).Assembly, typeof(DomainLayerClass).Assembly);
services.AddPipelineBehaviors();
The assembly parameters of AddApplication are used to configure MediatR (it will scan these assemblies for request and notification classes/handlers). In addition to this, the application layer assembly will by used to configure FluentValidation (it will use this assembly to scan for validators).
AddPipelineBehaviors adds the MediatR request pipelines behaviors listed in the Pipeline Behaviors section. This only needs to be added once per application/solution; not for once each project that uses this package.
Additional behaviors can be added as parameters to AddPipelineBehaviors.
Mediation
MediatR is used to assist with mediation, which allows the presentation layer of the application to have less dependencies e.g. API controller classes only need to inject the IMediator interface to handle web requests.
There a several interfaces that add a further layer of command-query responsibility separation (CQRS) on top of the IRequest interface in MediatR.
IQuery & ICommand
Query handlers that handle IQuery input types are required to have QueryResult as the return type. QueryResult has a type parameter that is used to specify the query data type.
Command handlers that handle ICommand input types are required to return a CommandResult.
Both QueryResult and CommandResult inherit from Result, which has the following properties.
IsSuccess- Whether the request was successful.
Status- An ResultStatus enum used to specify the type of result.
Errors- A dictionary keyed by request property for any errors encountered
Sample Code
ITenantRequest
ITenantedRequest has a TenantId Guid property used to specify the tenant ID for multi-tenanted applications.
ITenantRequest implementations are used by Lewee.Auth.Application's TenantLoggingBehavior (which decorates
logs with the tenant ID) and TenantRoleAuthorizationBehavior (which authorizes tenant-role-restricted requests);
see Lewee.Auth.Application for details.
Pipeline Behaviors
- CorelationIdLoggingBehavior
- Adds a
CorrelationIdstructured logging property for every request, resolved from the ambientICorrelationContextAccessor.
- Adds a
- DomainExceptionBehavior
- Catches DomainException, which is defined in the Lewee.Domain package, and returns a failure result.
- FailureLoggingBehavior
- Checks the
Statusof requests that haveResultreturn types and logs an error if there was an unexpected failure, or an information log if there was domain/validation failure.
- Checks the
- PerformanceLoggingBehavior
- Logs the time taken to execute the request using high-performance logging.
- UnhandledExceptionBehavior
- Catches unhandled exceptions and logs them as errors
- ValidationBehavior
- Executes
FluentValidationvalidators for the request and returns aCommandResultwith the errors dictionary populated if there are validation errors found, otherwise the rest of the pipeline is executed.
- Executes
Additional, opt-in behaviors for tenant logging and authorization are provided by Lewee.Auth.Application.
ClientEvent Notification
The ClientEvent can be published via MediatR.IMediator.Publish to broadcast an event to connected Blazor clients. The ClientEvent is handled by infrastructure in the Lewee.Infrastructure.ServerEvents package, which writes the event to an SSE channel for streaming to clients.
For the complete server-sent events infrastructure implementation, see the Lewee.Infrastructure.ServerEvents package.
Sample
Note: The current Pizzeria sample application demonstrates the ClientEvent pattern with the StartOrderCompletedAction being dispatched when an order is created.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Correlate.DependencyInjection (>= 6.1.1)
- FluentValidation.DependencyInjectionExtensions (>= 12.2.0)
- Lewee.Domain (>= 0.40.3)
- MediatR (>= 12.5.0)
- Microsoft.Extensions.Configuration.Binder (>= 11.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Lewee.Application:
| Package | Downloads |
|---|---|
|
Lewee.Infrastructure.AspNet
Package Description |
|
|
Lewee.Auth.Application
Package Description |
|
|
Lewee.Infrastructure.FastEndpoints
Package Description |
|
|
Lewee.Infrastructure.ServerEvents
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.40.3 | 55 | 11/22/2026 |
| 0.23.0 | 390 | 6/14/2024 |
| 0.22.0 | 312 | 6/3/2024 |
| 0.21.0 | 385 | 9/24/2023 |
| 0.20.0-alpha.1 | 132 | 9/24/2023 |
| 0.17.0-alpha.1 | 184 | 9/23/2023 |
| 0.16.0-alpha.1 | 184 | 9/23/2023 |
| 0.10.0 | 336 | 9/19/2023 |
| 0.9.0 | 296 | 9/17/2023 |
| 0.8.0 | 328 | 9/3/2023 |
| 0.7.0 | 331 | 9/3/2023 |
| 0.6.0 | 303 | 9/1/2023 |
| 0.5.3 | 342 | 8/25/2023 |
| 0.1.0 | 448 | 3/28/2023 |