Lewee.Application
0.9.0
See the version list below for details.
dotnet add package Lewee.Application --version 0.9.0
NuGet\Install-Package Lewee.Application -Version 0.9.0
<PackageReference Include="Lewee.Application" Version="0.9.0" />
paket add Lewee.Application --version 0.9.0
#r "nuget: Lewee.Application, 0.9.0"
// Install Lewee.Application as a Cake Addin #addin nuget:?package=Lewee.Application&version=0.9.0 // Install Lewee.Application as a Cake Tool #tool nuget:?package=Lewee.Application&version=0.9.0
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
Both IQuery
and ICommand
implement IApplicationRequest, which has a CorrelationId
Guid
property.
As mentioned in the Pipeline Behaviors section, the CorrelationId
property is used in the CorelationIdLoggingBehavior
to decorate the logs with the correlation ID for every Mediatr
request that implements IApplicationRequest
.
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.
As mentioned in the Pipeline Behaviors section, the TenantId
property is used in the TenantLoggingBehavior
to decorate the logs with tenant ID for every Mediatr
request that implements ITenantedRequest
.
Pipeline Behaviors
- CorelationIdLoggingBehavior
- Adds a
CorrelationId
structured logging property for every request. UsesCorrelationId
property if the request implemenatsIApplicationRequest
, otherwise it generates a new GUID.
- Adds a
- DomainExceptionBehavior
- Catches DomainException, which is defined in the Lewee.Domain package, and returns a failure result.
- FailureLoggingBehavior
- Checks the
Status
of requests that haveResult
return types and logs an error if there was an unexpected failure, or an information log if there was domain/validation failure.
- Checks the
- PerformanceLoggingBehavior
- Uses
Serilog
'sBeginTimedOperation
functionality to log the time taken to execute the request.
- Uses
- TenantLoggingBehavior
- Adds a
TenantId
structured logging property for every request that implementsITenantedRequest
.
- Adds a
- UnhandledExceptionBehavior
- Catches unhandled exceptions and logs them as errors
- ValidationBehavior
- Executes
FluentValidation
validators for the request and returns aCommandResult
with the errors dictionary populated if there are validation errors found, otherwise the rest of the pipeline is executed.
- Executes
ClientEvent Notification
The ClientEvent can be published via Mediatr.IMediator.Publish
to send a SignalR
event to the a client application.
Sample
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- FluentValidation.DependencyInjectionExtensions (>= 11.7.1)
- Lewee.Contracts (>= 0.9.0)
- Lewee.Domain (>= 0.9.0)
- MediatR (>= 12.1.1)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Serilog (>= 3.0.1)
- SerilogMetrics (>= 2.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Lewee.Application:
Package | Downloads |
---|---|
Lewee.Infrastructure.AspNet
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.23.0 | 153 | 6/14/2024 |
0.22.0 | 119 | 6/3/2024 |
0.21.0 | 244 | 9/24/2023 |
0.20.0-alpha.1 | 66 | 9/24/2023 |
0.17.0-alpha.1 | 74 | 9/23/2023 |
0.16.0-alpha.1 | 75 | 9/23/2023 |
0.10.0 | 175 | 9/19/2023 |
0.9.0 | 150 | 9/17/2023 |
0.8.0 | 161 | 9/3/2023 |
0.7.0 | 177 | 9/3/2023 |
0.6.0 | 140 | 9/1/2023 |
0.5.3 | 188 | 8/25/2023 |
0.1.0 | 239 | 3/28/2023 |