psosnicki / sample-dotnet-cqrs-eventstore-elasticsearch-projection

Sample .NET Core Web API - CQRS and Event Sourcing implementation with Event Store and Elasticsearch projections

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sample-dotnet-cqrs-eventstore-elasticsearch-projection

build

Sample .NET Core Web API - CQRS and Event Sourcing implementation with Event Store and Elasticsearch projections

alt text

Sample projection

public class UserViewProjection : Projection<UserView>
{
    public UserViewProjection(IViewRepository<UserView> viewRepository) : base(viewRepository)
    {
        Project<UserCreatedEvent>(OnUserCreated, e => e.UserId);
        Project<UserEmailUpdatedEvent>(OnUserEmailUpdated, e => e.UserId);
    }

    public async ValueTask<UserView> OnUserEmailUpdated(UserEmailUpdatedEvent @event, UserView view, CancellationToken cancellationToken)
    {
        return view with
        {
            Email = @event.Email
        };
    }

    public async ValueTask<UserView> OnUserCreated(UserCreatedEvent @event, UserView view, CancellationToken cancellationToken)
    {
        return view with
        {
            Id = @event.UserId,
            Firstname = @event.Firstname,
            Lastname = @event.Lastname,
            Email = @event.Email,
            Fullname = $"{@event.Firstname} {@event.Lastname}"
        };
    }
}

Demo

docker-compose up
http://localhost:5001/swagger

Give a ⭐ if you like :) Thanks

About

Sample .NET Core Web API - CQRS and Event Sourcing implementation with Event Store and Elasticsearch projections


Languages

Language:C# 99.1%Language:Dockerfile 0.9%