eventflow / EventFlow

Async/await first CQRS+ES and DDD framework for .NET
https://geteventflow.net
Other
2.39k stars 445 forks source link

Allow persistence to be explicitly selected #1034

Open rlf opened 5 months ago

rlf commented 5 months ago

With the current extension methods, it would seem that the following would be selecting PostgreSql as persisitence:

services.AddEventFlow(o => o.UsePostgreSqlEventStore());

Unfortunately that is not the case, since the TryAdd in this line: https://github.com/eventflow/EventFlow/blob/develop-v1/Source/EventFlow.PostgreSql/Extensions/EventFlowOptionsPostgresSqlEventStoreExtensions.cs#L34

Won't replace the TryAdd in this line: https://github.com/eventflow/EventFlow/blob/bb46378162511b53989f6f94357126bc76673dc1/Source/EventFlow/EventFlowOptions.cs#L185

A current workaround would be to either do:

services.TryAddTransient<IEventPersistence, PostgreSqlEventPersistence>();
services.AddEventFlow(o => {});

or

services.AddEventFlow(o => {});
services.AddTransient<IEventPersistence, PostgreSqlEventPersistence>();

But to me it seems that if you specifically use the UsePostgreSqlEventStore extension, it should be safe to add without try (i.e. overrule the sane defaults).

rasmus commented 5 months ago

Seems like a good change and possible a mistake on my part when I moved everything to the new extensions