diff --git a/README.md b/README.md index 8620254..5a187b8 100644 --- a/README.md +++ b/README.md @@ -45,15 +45,30 @@ Here are some basic examples of how to use the library: ### Setup +Create your domain objects + +```csharp +// domain.cs + +public class TestState +{ + public required Guid Id { get; set; } + public string? Test { get; set; } +} + +``` + Add the aggregate to the service collection ```csharp +// program.cs + using StreamWave; using StreamWave.EntityFramework; var builder = WebApplication.CreateBuilder(args); -builder.Services.AddAggregate(() => new TestState() { Id = Guid.NewGuid() }) +builder.Services.AddAggregate((id) => new TestState() { Id = id }) .WithEntityFramework() .WithApplier((s, e) => { @@ -67,13 +82,14 @@ builder.Services.AddAggregate(() => new TestState() { Id = Gui ```csharp -public Task HandleAsync(IAggregate aggregate, Guid id) +public async Task HandleAsync(IAggregateManager manager, Guid id) { - aggregate.LoadAsync(id); + var aggregate = manager.LoadAsync(id); aggregate.Apply(new TestEvent("Update")); -} + await manager.SaveAsync(aggregate); +} ``` diff --git a/StreamWave.sln b/StreamWave.sln index 33b8752..33b067f 100644 --- a/StreamWave.sln +++ b/StreamWave.sln @@ -34,7 +34,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StreamWave.EntityFramework. EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "example", "example", "{40B48187-5A59-4A8B-AA36-8E9C33278F0A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApp", "examples\SampleApp\SampleApp.csproj", "{E81E8206-445E-4009-ADA6-850370A77951}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleApp", "examples\SampleApp\SampleApp.csproj", "{E81E8206-445E-4009-ADA6-850370A77951}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{84700FAC-774E-4E46-A3E3-3AD45672C938}" + ProjectSection(SolutionItems) = preProject + docs\getting-started.md = docs\getting-started.md + docs\introduction.md = docs\introduction.md + docs\toc.yml = docs\toc.yml + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/docs/getting-started.md b/docs/getting-started.md index 8b3a794..2e8f6c2 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1 +1,14 @@ -# Getting Started \ No newline at end of file +# Getting Started + +To get started with StreamWave in your .NET Core project follow these steps: + +## 1. Installation + +Add StreamWave to your project via Nuget Package Manager: + +```bash +dotnet add package StreamWave +``` + +## 2. Create your domain objects + diff --git a/docs/introduction.md b/docs/introduction.md index f6ecaa6..6b737b5 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -1 +1,7 @@ -# Introduction \ No newline at end of file +# Introduction + +## StreamWave + +StreamWave is an aggregate root library designed for streaming environments, aimed at addressing the dual write problem by decoupling the domain model from the event stream. It allows easy integration with .NET Core projects, providing a streamlined approach to managing aggregates and event sourcing. The library offers seamless setup and configuration, ensuring efficient handling of state changes and event applications. Contributions to the project are welcome, and it is licensed under the MIT License. + +For more details, visit the [StreamWave GitHub repository](https://github.com/pmdevers/StreamWave). diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 37daa09..147c0f8 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -38,6 +38,7 @@ True \ + false True diff --git a/src/StreamWave/Aggregate.cs b/src/StreamWave/Aggregate.cs index 1b9b46b..33475c5 100644 --- a/src/StreamWave/Aggregate.cs +++ b/src/StreamWave/Aggregate.cs @@ -74,10 +74,11 @@ ValidateStateDelegate validator _version++; _createdOn ??= e.OccurredOn; _lastModiefiedOn = e.OccurredOn; - return _applier(state, e); + return _applier(state, e.Event); })); - runner.Wait(); + + } public TId Id { get; private set; }