Lewee.Application 0.20.0-alpha.1

This is a prerelease version of Lewee.Application.
This package has a SemVer 2.0.0 package version: 0.20.0-alpha.1+4.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Lewee.Application --version 0.20.0-alpha.1                
NuGet\Install-Package Lewee.Application -Version 0.20.0-alpha.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lewee.Application" Version="0.20.0-alpha.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Lewee.Application --version 0.20.0-alpha.1                
#r "nuget: Lewee.Application, 0.20.0-alpha.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Lewee.Application as a Cake Addin
#addin nuget:?package=Lewee.Application&version=0.20.0-alpha.1&prerelease

// Install Lewee.Application as a Cake Tool
#tool nuget:?package=Lewee.Application&version=0.20.0-alpha.1&prerelease                

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
  • Errors
    • A dictionary keyed by request property for any errors encountered
Sample Code

Query

Command

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. Uses CorrelationId property if the request implemenats IApplicationRequest, otherwise it generates a new GUID.
  • DomainExceptionBehavior
  • FailureLoggingBehavior
    • Checks the Status of requests that have Result return types and logs an error if there was an unexpected failure, or an information log if there was domain/validation failure.
  • PerformanceLoggingBehavior
    • Uses Serilog's BeginTimedOperation functionality to log the time taken to execute the request.
  • TenantLoggingBehavior
    • Adds a TenantId structured logging property for every request that implements ITenantedRequest.
  • UnhandledExceptionBehavior
    • Catches unhandled exceptions and logs them as errors
  • ValidationBehavior
    • Executes FluentValidation validators for the request and returns a CommandResult with the errors dictionary populated if there are validation errors found, otherwise the rest of the pipeline is executed.

ClientEvent Notification

The ClientEvent can be published via Mediatr.IMediator.Publish to send a SignalR event to the a client application.

Sample

Client Event.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 156 6/14/2024
0.22.0 122 6/3/2024
0.21.0 247 9/24/2023
0.20.0-alpha.1 67 9/24/2023
0.17.0-alpha.1 75 9/23/2023
0.16.0-alpha.1 76 9/23/2023
0.10.0 178 9/19/2023
0.9.0 153 9/17/2023
0.8.0 164 9/3/2023
0.7.0 180 9/3/2023
0.6.0 143 9/1/2023
0.5.3 191 8/25/2023
0.1.0 242 3/28/2023