CascadeEsdm.Views 1.0.0-beta.12

This is a prerelease version of CascadeEsdm.Views.
This package has a SemVer 2.0.0 package version: 1.0.0-beta.12+883e346.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package CascadeEsdm.Views --version 1.0.0-beta.12
                    
NuGet\Install-Package CascadeEsdm.Views -Version 1.0.0-beta.12
                    
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="CascadeEsdm.Views" Version="1.0.0-beta.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CascadeEsdm.Views" Version="1.0.0-beta.12" />
                    
Directory.Packages.props
<PackageReference Include="CascadeEsdm.Views" />
                    
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 CascadeEsdm.Views --version 1.0.0-beta.12
                    
#r "nuget: CascadeEsdm.Views, 1.0.0-beta.12"
                    
#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 CascadeEsdm.Views@1.0.0-beta.12
                    
#: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=CascadeEsdm.Views&version=1.0.0-beta.12&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CascadeEsdm.Views&version=1.0.0-beta.12&prerelease
                    
Install as a Cake Tool

Cascade.Views

View/Query implementation for the Cascade Event Sourcing framework.

Overview

This package provides the concrete implementation of query handling infrastructure for event-sourced systems. It includes query bus, handler registration, projection management, and view materialization support.

Features

  • Query Bus: In-memory query dispatcher
  • Handler Registration: Automatic discovery and registration of query handlers
  • Projection Engine: Event-driven view materialization
  • View Repositories: Abstractions for storing and retrieving read models
  • Dependency Injection: First-class support for Microsoft.Extensions.DependencyInjection
  • Caching Support: Built-in caching strategies for views

Installation

dotnet add package Cascade.Views

This will automatically include:

  • Cascade.Views.Abstractions

Usage

Register Query Handlers

using Cascade.Views;

services.AddCascadeViews(options =>
{
    options.RegisterHandlersFromAssembly(typeof(GetOrderByIdHandler).Assembly);
    options.RegisterProjectionsFromAssembly(typeof(OrderProjection).Assembly);
});

Implement a Query Handler

public class GetOrderByIdHandler : IQueryHandler<GetOrderByIdQuery, OrderView>
{
    private readonly IViewRepository<OrderView> _repository;
    
    public GetOrderByIdHandler(IViewRepository<OrderView> repository)
    {
        _repository = repository;
    }
    
    public async Task<OrderView?> HandleAsync(
        GetOrderByIdQuery query, 
        CancellationToken cancellationToken)
    {
        return await _repository.GetByIdAsync(query.OrderId.ToString(), cancellationToken);
    }
}

Execute Queries

public class OrderController : ControllerBase
{
    private readonly IQueryBus _queryBus;
    
    public OrderController(IQueryBus queryBus)
    {
        _queryBus = queryBus;
    }
    
    [HttpGet("{id}")]
    public async Task<IActionResult> GetOrder(string id)
    {
        var query = new GetOrderByIdQuery(new OrderId(id));
        var view = await _queryBus.QueryAsync(query);
        
        return view != null ? Ok(view) : NotFound();
    }
}

Implement a Projection

public class OrderProjection : IProjection<OrderView>
{
    private readonly IViewRepository<OrderView> _repository;
    
    public OrderProjection(IViewRepository<OrderView> repository)
    {
        _repository = repository;
    }
    
    public async Task ProjectAsync(DomainEvent @event, CancellationToken cancellationToken)
    {
        switch (@event)
        {
            case OrderPlaced e:
                await HandleOrderPlaced(e, cancellationToken);
                break;
            case OrderShipped e:
                await HandleOrderShipped(e, cancellationToken);
                break;
        }
    }
    
    private async Task HandleOrderPlaced(OrderPlaced @event, CancellationToken cancellationToken)
    {
        var view = new OrderView
        {
            Id = @event.OrderId.ToString(),
            CustomerId = @event.CustomerId.ToString(),
            Status = "Placed",
            CreatedAt = @event.Timestamp
        };
        
        await _repository.SaveAsync(view, cancellationToken);
    }
    
    private async Task HandleOrderShipped(OrderShipped @event, CancellationToken cancellationToken)
    {
        var view = await _repository.GetByIdAsync(@event.OrderId.ToString(), cancellationToken);
        if (view != null)
        {
            view.Status = "Shipped";
            await _repository.UpdateAsync(view, cancellationToken);
        }
    }
}

Dependencies

  • Cascade.Views.Abstractions
  • Cascade.Commands: Command handling for the write side
  • Cascade.Storage.CosmosDb: Persistence implementation for views

Documentation

For complete documentation, examples, and best practices, visit: https://github.com/tsgenge/cascade

License

BSD 3-Clause License - see LICENSE file for details

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated