/StreamWave

An aggregate root for use in a streaming environment to solve the dual write problem by separating domain model from the event stream

Primary LanguageC#MIT LicenseMIT

StreamWave AggregateRoot

Github Release GitHub Actions Workflow Status GitHub License Github Issues Open Github Pull Request Open Scheduled Code Security Testing

An aggregate root designed for a streaming environment, addressing the dual write problem by decoupling the domain model from the event stream.

Alt text

Table of Contents

Features

  • Easy integration

Installation

To install the package, use the following command in your .NET Core project:

dotnet add package StreamWave

Alternatively, you can add it manually to your .csproj file:

<PackageReference Include="StreamWave" Version="0.1.0" />

Usage

Here are some basic examples of how to use the library:

Setup

Create your domain objects

// domain.cs

public class TestState 
{
    public required Guid Id { get; set; }
    public string? Test { get; set; }
}

Add the aggregate to the service collection

// program.cs

using StreamWave;
using StreamWave.EntityFramework;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAggregate<TestState, Guid>((id) => new TestState() {  Id = id })
            .WithEntityFramework<TestContext, TestState, Guid>()
            .WithApplier<TestEvent>((s, e) =>
            {
                s.Test = e.Field;
                return s;
            });

Use

public async Task HandleAsync(IAggregateManager<TestState, Guid> manager, Guid id)
{
    var aggregate = manager.LoadAsync(id);

    aggregate.Apply(new TestEvent("Update"));

    await manager.SaveAsync(aggregate);
}

Configuration

[TODO]

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you encounter any bugs or have feature requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.