Lewee.Application 0.40.3

dotnet add package Lewee.Application --version 0.40.3
                    
NuGet\Install-Package Lewee.Application -Version 0.40.3
                    
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.40.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lewee.Application" Version="0.40.3" />
                    
Directory.Packages.props
<PackageReference Include="Lewee.Application" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lewee.Application --version 0.40.3
                    
#r "nuget: Lewee.Application, 0.40.3"
                    
#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.
#:package Lewee.Application@0.40.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lewee.Application&version=0.40.3
                    
Install as a Cake Addin
#tool nuget:?package=Lewee.Application&version=0.40.3
                    
Install as a Cake Tool

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
  • 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.

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 CorrelationId structured logging property for every request, resolved from the ambient ICorrelationContextAccessor.
  • 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
    • Logs the time taken to execute the request using high-performance logging.
  • 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.

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 Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.ServerEvents

Package Description

Lewee.Infrastructure.FastEndpoints

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.40.3 60 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