Skip to content

Commit

Permalink
Merge pull request #1035 from eventflow/rasmus/explicit-persistence-s…
Browse files Browse the repository at this point in the history
…election

Fix: Proper registration of event persistence layer
  • Loading branch information
rasmus authored Dec 24, 2024
2 parents 9ab17f9 + 793f34d commit 01261e3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 9 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### New in 1.1.1 (working version, not released yet)

* Fix: Invoking `UseEventPersistence` now removes any previously registered event persistence. This
fixes a service ordering issue in the following event store configurations
- MongoDB
- MSSQL
- PostgreSQL


### New in 1.1.0 (released 2024-12-16)

* New: More control of event naming by introducing the interface `IEventNamingStrategy`, see the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<IsPackable>False</IsPackable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\**" />
<EmbeddedResource Remove="Properties\**" />
<None Remove="Properties\**" />
</ItemGroup>

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

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="NUnit" Version="3.13.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using EventFlow.EventStores;
using EventFlow.Extensions;
using EventFlow.PostgreSql.EventStores;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace EventFlow.PostgreSql.Extensions
{
public static class EventFlowOptionsPostgreSqlEventStoreExtensions
{
public static IEventFlowOptions UsePostgreSqlEventStore(this IEventFlowOptions eventFlowOptions)
{
return eventFlowOptions.RegisterServices(f => f.TryAddTransient<IEventPersistence, PostgreSqlEventPersistence>());
return eventFlowOptions.UseEventPersistence<PostgreSqlEventPersistence>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using EventFlow.EventStores;
using EventFlow.EventStores.Files;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace EventFlow.Extensions
{
Expand All @@ -34,8 +35,7 @@ public static IEventFlowOptions UseEventPersistence(
Func<IServiceProvider, IEventPersistence> eventPersistenceResolver,
ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
{
eventFlowOptions.ServiceCollection
.Add(new ServiceDescriptor(typeof(IEventStore), eventPersistenceResolver, serviceLifetime));
eventFlowOptions.ServiceCollection.Add(new ServiceDescriptor(typeof(IEventStore), eventPersistenceResolver, serviceLifetime));
return eventFlowOptions;
}

Expand All @@ -44,8 +44,8 @@ public static IEventFlowOptions UseEventPersistence<TEventPersistence>(
ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
where TEventPersistence : class, IEventPersistence
{
eventFlowOptions.ServiceCollection
.Add(new ServiceDescriptor(typeof(IEventPersistence), typeof(TEventPersistence), serviceLifetime));
eventFlowOptions.ServiceCollection.RemoveAll<IEventPersistence>();
eventFlowOptions.ServiceCollection.Add(new ServiceDescriptor(typeof(IEventPersistence), typeof(TEventPersistence), serviceLifetime));
return eventFlowOptions;
}

Expand Down

0 comments on commit 01261e3

Please sign in to comment.