Skip to content

Commit

Permalink
Merge branch 'develop-v1' into update-eventstores-eventstore
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus authored Dec 24, 2024
2 parents 09ef7b9 + 9ab17f9 commit cf2d808
Show file tree
Hide file tree
Showing 31 changed files with 446 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
2.1.x
3.1.x
6.0.x
8.0.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
File renamed without changes.
56 changes: 41 additions & 15 deletions .github/workflows/ci.yml → .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
name: CI
name: pipeline

on:
push:
branches: [ develop-v1 ]
pull_request:
branches: [ develop-v1 ]
workflow_call:
inputs:
# REQUIRED ============================
version:
required: true
type: string
# OPTIONAL ============================
bake-convention:
required: false
default: 'default'
type: string
bake-version:
required: false
type: string
default: '0.30.43-beta'
environment:
required: false
type: string
default: 'develop'
secrets:
nuget-api-key:
required: false

jobs:
build:
runs-on: ubuntu-20.04
runs-on:
- ubuntu-20.04

environment:
name: ${{ inputs.environment }}

env:
HELPZ_POSTGRESQL_PASS: Password12!
EVENTFLOW_MSSQL_SERVER: 127.0.0.1,1433
EVENTFLOW_MSSQL_USER: sa
EVENTFLOW_MSSQL_PASS: Password12!
EVENTFLOW_MSSQL_PASS: Password12!
NUGET_APIKEY: ${{ secrets.nuget-api-key }}

services:
rabbitmq:
image: rabbitmq:3.12.0-management-alpine
image: rabbitmq:3-management-alpine
env:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
Expand Down Expand Up @@ -65,7 +89,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version:
dotnet-version: |
3.1.x
6.0.x
8.0.x
Expand All @@ -76,19 +100,21 @@ jobs:

# https://github.com/rasmus/Bake
- name: Install Bake
run: dotnet tool install -g --version 0.23.36-beta Bake
run: dotnet tool install -g --version ${{ inputs.bake-version }} Bake

- name: Run Bake
run: |
declare -i REVISION
REVISION=5000+$GITHUB_RUN_NUMBER
bake run --build-version 1.0.$REVISION
env:
MKDOCS_GIT_COMMITTERS_APIKEY: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bake run \
--convention=${{ inputs.bake-convention }} \
--build-version ${{ inputs.version }} \
--destination="nuget>github,nuget,release>github"
- name: Upload NuGet packages
uses: actions/upload-artifact@v4
if: success() || failure()
if: success()
with:
name: packages
path: "**/*nupkg"
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/pull-requests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: pull-requests

on:
push:
branches: [ develop-v1 ]
pull_request:
branches: [ develop-v1 ]

permissions:
contents: read

jobs:
pipeline:
uses: ./.github/workflows/pipeline.yaml
with:
version: "1.1.0-pr${{ github.event.number }}-b${{ github.run_number }}"
19 changes: 19 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: release

on:
push:
branches: [ release-v1 ]

permissions:
contents: write
packages: write

jobs:
pipeline:
uses: ./.github/workflows/pipeline.yaml
with:
bake-convention: 'Release'
environment: 'release'
version: "1.1.0"
secrets:
nuget-api-key: ${{ secrets.NUGET_APIKEY }}
97 changes: 0 additions & 97 deletions .github/workflows/release.yml

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Test report
name: test reports

on:
workflow_run:
workflows:
- 'CI'
- 'Release'
- 'pull-requests'
- 'release'
types:
- completed

Expand Down
31 changes: 31 additions & 0 deletions Documentation/additional/event-naming-strategies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Event Naming Strategies
---

# Event Naming Strategies

Event classes with the same name but in different namespaces can potentially collide, when EventFlow just handles the classname. This can potentially lead to errors as EventFlow doesn't know which event class it should rehydrate and apply to.
In order to avoid this, EventFlow incorporates the concept of event naming strategies that can be used to uniquely identify each event class.


## Built-In Strategies

There are a few naming strategies already available in EventFlow out-of-the-box:

- `DefaultStrategy`: The **default behaviour**, if not overwritten explicitly. This strategy will use the className or (if provided) the value coming from an `[EventVersion]` attribute. This matches the implicit naming strategy from previous EventFlow versions.

- `NamespaceAndNameStrategy`: This strategy uses both the namespace and the class name or (if provided) the value coming from an `[EventVersion]` attribute to uniquely identify an event class.
- `NamespaceAndClassNameStrategy`: This strategy uses both the namespace and the class name to uniquely identify an event class. Any name value coming from an `[EventVersion]` attribute will be ignored for internal naming.

## Custom Strategies

All Event Naming Strategies implement the `IEventNamingStrategy` interface.:

```csharp
public interface IEventNamingStrategy
{
public string CreateEventName(int version, Type eventType, string name);
}
```

One can come up with their own strategy by implementing this interface and registering it with EventFlow.
4 changes: 2 additions & 2 deletions Documentation/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ public class ExampleEvent : AggregateEvent<ExampleAggregate, ExampleId>
}
```

We have applied the `[EventVersion("example", 1)]` to our event, marking it as the `example` event version `1`, which directly corresponds to the `event_name` and `event_version` from the metadata stored alongside the event mentioned. The information is used by EventFlow to tie the name and version to a specific .NET type.
We have applied the `[EventVersion("example", 1)]` to our event, marking it as the `example` event version `1`, which directly corresponds to the `event_name` and `event_version` from the metadata stored alongside the event mentioned. The information is used by EventFlow to tie the name and version to a specific .NET type. This is important when reading events from the event store as EventFlow needs to know which type to deserialize the event to. If an alternative default naming convention is needed, read our section on [event naming strategies](additional/event-naming-strategies.md).

!!! warning
Even though using the `EventVersion` attribute is optional, it is **highly recommended**. EventFlow will infer the information if it isn't provided, thus making it vulnerable to type renames among other things.
Even though using the `EventVersion` attribute is optional, it is **highly recommended**. EventFlow will infer the information if it isn't provided, thus making it vulnerable to type renames among other things. Read our section on [event naming strategies](additional/event-naming-strategies.md) if an alternative default naming convention is needed.

!!! danger
Once you have aggregates in your production environment that have emitted an event, you should never change the .NET implementation of the event! You can deprecate it, but you should never change the type or the data stored in the event store. If the event type is changed, EventFlow will not be able to deserialize the event and can produce unexpected results when reading old aggregates.
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,8 @@ category.

## Thanks

<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="25%">
<a href="https://www.jetbrains.com/"><img src="./Resources/jetbrains-128x128.png" /></a>
</td>
</tr>
</table>

![JetBrains logo](https://raw.githubusercontent.com/eventflow/EventFlow/develop-v1/Resources/jetbrains-128x128.png)
* [Contributors](https://github.com/eventflow/EventFlow/graphs/contributors)
* [JetBrains](https://www.jetbrains.com/resharper/): OSS licenses
Expand Down
8 changes: 7 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
### New in 1.0-alpha (not properly released yet)
### New in 1.1.0 (released 2024-12-16)

* New: More control of event naming by introducing the interface `IEventNamingStrategy`, see the
updated documentation at https://geteventflow.net/additional/event-naming-strategies/ for more
information (thanks @SeWaS)

### New in 1.0.5007 (released 2024-11-16)

Read the complete migration guide to get the full list of changes as well as recommendations
on how to do the migration.
Expand Down
1 change: 1 addition & 0 deletions Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<NuGetAudit>false</NuGetAudit>
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
<NoWarn>1701;1702;1705;1591;NU1901;NU1902;NU1903;NU1904</NoWarn>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
Expand Down
5 changes: 4 additions & 1 deletion Source/EventFlow.Tests/IntegrationTests/UnicodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using EventFlow.Aggregates;
using EventFlow.Commands;
using EventFlow.Configuration;
using EventFlow.Configuration.EventNamingStrategy;
using EventFlow.Core;
using EventFlow.EventStores;
using EventFlow.Extensions;
Expand Down Expand Up @@ -94,7 +95,8 @@ public void UnicodeEvents()
// Arrange
var eventDefinitionService = new EventDefinitionService(
Mock<ILogger<EventDefinitionService>>(),
Mock<ILoadedVersionedTypes>());
Mock<ILoadedVersionedTypes>(),
new DefaultStrategy());

// Act
Action action = () => eventDefinitionService.Load(typeof(Püng1Event));
Expand All @@ -110,6 +112,7 @@ public async Task UnicodeIntegration()
.AddEvents(typeof(Püng1Event))
.AddCommands(typeof(Cömmand))
.AddCommandHandlers(typeof(CömmandHändler))
.RegisterServices(s => s.AddScoped<IEventNamingStrategy, NamespaceAndClassNameStrategy>())
.ServiceCollection.BuildServiceProvider();

var bus = resolver.GetRequiredService<ICommandBus>();
Expand Down
Loading

0 comments on commit cf2d808

Please sign in to comment.