XperienceCommunity.CQRS.Data
1.0.0-prerelease-7-1
See the version list below for details.
dotnet add package XperienceCommunity.CQRS.Data --version 1.0.0-prerelease-7-1
NuGet\Install-Package XperienceCommunity.CQRS.Data -Version 1.0.0-prerelease-7-1
<PackageReference Include="XperienceCommunity.CQRS.Data" Version="1.0.0-prerelease-7-1" />
paket add XperienceCommunity.CQRS.Data --version 1.0.0-prerelease-7-1
#r "nuget: XperienceCommunity.CQRS.Data, 1.0.0-prerelease-7-1"
// Install XperienceCommunity.CQRS.Data as a Cake Addin #addin nuget:?package=XperienceCommunity.CQRS.Data&version=1.0.0-prerelease-7-1&prerelease // Install XperienceCommunity.CQRS.Data as a Cake Tool #tool nuget:?package=XperienceCommunity.CQRS.Data&version=1.0.0-prerelease-7-1&prerelease
Xperience Community - CQRS
A CQRS implementation influenced by https://github.com/jbogard/MediatR/ combined with https://github.com/vkhorikov/CSharpFunctionalExtensions for Kentico Xperience applications.
Dependencies
This package is compatible with ASP.NET Core 6+ and is designed to be used with .NET Core / .NET 6 applications integrated with Kentico Xperience 13.0.
How to Use?
This library is separated into (3) NuGet packages. Each package is associated with a different part of the Onion Architecture. You can install all of these into your web application project or isolate your Kentico Xperience types behind abstractions.
XperienceCommunity.CQRS.Core
- Abstractions and implementations for the Domain, Persistence, and Presentation layers to implement.
- Typically the project consuming this package doesn't have any reference to Kentico Xperience packages or APIs.
XperienceCommunity.CQRS.Data
- Decorators and base classes for data access implementations.
- The project consuming this package also uses Kentico Xperience data access APIs.
XperienceCommunity.CQRS.Web
- Presentation layer cache and service collection registration utilities.
- The project consuming this package is where your presentation logic is located (Razor/View Components/Controllers).
First, install the NuGet package(s) in your ASP.NET Core projects (see the example project under /samples)
dotnet add package XperienceCommunity.CQRS.Core dotnet add package XperienceCommunity.CQRS.Data dotnet add package XperienceCommunity.CQRS.Web
Create a new implementation of
IQuery<T>
public record HomePageQuery : IQuery<HomePageQueryData>; public record HomePageQueryData(string Title, Maybe<string> BodyHTML);
Create a new implementation of
IQueryHandler<TQuery, TResponse>
public class HomePageQueryHandler : CacheableQueryHandler<HomePageQuery, HomePageQueryData> { private readonly IPageRetriever retriever; public HomePageQueryHandler(IPageRetriever retriever) => this.retriever = retriever; public override Task<Result<HomePageQueryData>> Execute(HomePageQuery query, CancellationToken token) => pageRetriever.RetrieveAsync<HomePage>(q => q.TopN(1), cancellationToken: token) .TryFirst() .ToResult($"Could not find any [{HomePage.CLASS_NAME}]") .Map(homePage => { var bodyHTML = string.IsNullOrWhiteSpace(p.Fields.BodyHTML) ? Maybe<string>.None : p.Fields.BodyHTML; return new HomePageQueryData(homePage.Fields.Title, bodyHTML); }); protected override ICacheDependencyKeysBuilder AddDependencyKeys( HomePageQuery query, HomePageQueryData response, ICacheDependencyKeysBuilder builder) => builder.PageType(HomePage.CLASS_NAME); }
Register the library's dependencies with the service collection
public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddCQRS(typeof(HomePageQueryHandler).Assembly); // ... } }
Use queries in your MVC Controllers, application services, or View Components
public class HomePageViewComponent : ViewComponent { private readonly IQueryDispatcher dispatcher; public HomePageViewComponent(IQueryDispatcher dispatcher) => this.dispatcher = dispatcher; public Task<IViewComponentResult> Invoke() => dispatcher.Dispatch(new HomePageQuery(), HttpContext.RequestAborted) .ViewWithFallbackOnFailure(this, "_HomePage", data => new HomePageViewModel(data)); }
@using Microsoft.AspNetCore.Html @using XperienceCommunity.Sandbox.Web.Features.Home.Components @model HomePageViewModel <h1>@Model.Title</h1> @Model.BodyHTML.GetValueOrDefault(HtmlString.Empty) @if (Model.ImagePath.HasValue) { <img src="@Model.ImagePath.GetValueOrThrow()" alt="@Model.Title" /> }
How Does It Work?
- TODO
Contributing
To build this project, you must have v6.0.300 or higher of the .NET SDK installed.
References
Kentico Xperience
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
-
net6.0
- CSharpFunctionalExtensions (>= 2.29.1)
- Kentico.Xperience.AspNetCore.WebApp (>= 13.0.16 && < 13.1.0)
- XperienceCommunity.CQRS.Core (>= 1.0.0-prerelease-7-1)
- XperienceCommunity.PageBuilderUtilities (>= 1.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on XperienceCommunity.CQRS.Data:
Package | Downloads |
---|---|
XperienceCommunity.CQRS.Web
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-prerelease-8-1 | 141 | 5/18/2022 |
1.0.0-prerelease-7-1 | 134 | 5/15/2022 |