Skip to content

Commit 01261e3

Browse files
authored
Merge pull request #1035 from eventflow/rasmus/explicit-persistence-selection
Fix: Proper registration of event persistence layer
2 parents 9ab17f9 + 793f34d commit 01261e3

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

RELEASE_NOTES.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### New in 1.1.1 (working version, not released yet)
2+
3+
* Fix: Invoking `UseEventPersistence` now removes any previously registered event persistence. This
4+
fixes a service ordering issue in the following event store configurations
5+
- MongoDB
6+
- MSSQL
7+
- PostgreSQL
8+
9+
110
### New in 1.1.0 (released 2024-12-16)
211

312
* New: More control of event naming by introducing the interface `IEventNamingStrategy`, see the

Source/EventFlow.PostgreSql.Tests/EventFlow.PostgreSql.Tests.csproj

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
44
<IsPackable>False</IsPackable>
55
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Remove="Properties\**" />
8+
<EmbeddedResource Remove="Properties\**" />
9+
<None Remove="Properties\**" />
10+
</ItemGroup>
611

712
<ItemGroup>
813
<None Remove="IntegrationTests\ReadStores\Scripts\0001 - Create table ReadModel-ThingyAggregate.sql" />
@@ -14,10 +19,6 @@
1419
<EmbeddedResource Include="IntegrationTests\ReadStores\Scripts\0002 - Create table ReadModel-ThingyMessage.sql" />
1520
</ItemGroup>
1621

17-
<ItemGroup>
18-
<Folder Include="Properties\" />
19-
</ItemGroup>
20-
2122
<ItemGroup>
2223
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
2324
<PackageReference Include="NUnit" Version="3.13.2" />

Source/EventFlow.PostgreSql/Extensions/EventFlowOptionsPostgresSqlEventStoreExtensions.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@
2020
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2121
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222

23-
using EventFlow.EventStores;
2423
using EventFlow.Extensions;
2524
using EventFlow.PostgreSql.EventStores;
26-
using Microsoft.Extensions.DependencyInjection.Extensions;
2725

2826
namespace EventFlow.PostgreSql.Extensions
2927
{
3028
public static class EventFlowOptionsPostgreSqlEventStoreExtensions
3129
{
3230
public static IEventFlowOptions UsePostgreSqlEventStore(this IEventFlowOptions eventFlowOptions)
3331
{
34-
return eventFlowOptions.RegisterServices(f => f.TryAddTransient<IEventPersistence, PostgreSqlEventPersistence>());
32+
return eventFlowOptions.UseEventPersistence<PostgreSqlEventPersistence>();
3533
}
3634
}
3735
}

Source/EventFlow/Extensions/EventFlowOptionsEventStoresExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using EventFlow.EventStores;
2525
using EventFlow.EventStores.Files;
2626
using Microsoft.Extensions.DependencyInjection;
27+
using Microsoft.Extensions.DependencyInjection.Extensions;
2728

2829
namespace EventFlow.Extensions
2930
{
@@ -34,8 +35,7 @@ public static IEventFlowOptions UseEventPersistence(
3435
Func<IServiceProvider, IEventPersistence> eventPersistenceResolver,
3536
ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
3637
{
37-
eventFlowOptions.ServiceCollection
38-
.Add(new ServiceDescriptor(typeof(IEventStore), eventPersistenceResolver, serviceLifetime));
38+
eventFlowOptions.ServiceCollection.Add(new ServiceDescriptor(typeof(IEventStore), eventPersistenceResolver, serviceLifetime));
3939
return eventFlowOptions;
4040
}
4141

@@ -44,8 +44,8 @@ public static IEventFlowOptions UseEventPersistence<TEventPersistence>(
4444
ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
4545
where TEventPersistence : class, IEventPersistence
4646
{
47-
eventFlowOptions.ServiceCollection
48-
.Add(new ServiceDescriptor(typeof(IEventPersistence), typeof(TEventPersistence), serviceLifetime));
47+
eventFlowOptions.ServiceCollection.RemoveAll<IEventPersistence>();
48+
eventFlowOptions.ServiceCollection.Add(new ServiceDescriptor(typeof(IEventPersistence), typeof(TEventPersistence), serviceLifetime));
4949
return eventFlowOptions;
5050
}
5151

0 commit comments

Comments
 (0)