forked from aneshas/tactical-ddd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
50 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 8 additions & 24 deletions
32
Tactical.DDD.EventSourcing.Postgres/Aperture/ApertureServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,25 @@ | ||
using System; | ||
using Aperture.Core; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Npgsql; | ||
using IPullEventStreamEventStore = Aperture.Core.IEventStore; | ||
|
||
namespace Tactical.DDD.EventSourcing.Postgres.Aperture | ||
{ | ||
public static class ApertureServiceCollectionExtensions | ||
{ | ||
public static void AddPostgresEventStream(this IServiceCollection services) => | ||
services.AddScoped<IPullEventStreamEventStore, EventStore>(); | ||
|
||
public static void AddPostgresAperture( | ||
this IServiceCollection services, | ||
PullEventStream.Config config = default, | ||
Func<ApertureAgent, ApertureAgent> configure = null) | ||
string connString, | ||
PullEventStream.Config config = default | ||
) | ||
{ | ||
services.AddScoped<PostgresOffsetTracker>(); | ||
services.AddTransient(_ => NpgsqlDataSource.Create(connString)); | ||
services.AddTransient<IPullEventStreamEventStore, EventStore>(); | ||
services.AddSingleton<ITrackOffset, PostgresOffsetTracker>(); | ||
|
||
services.AddScoped<IStreamEvents>( | ||
services.AddTransient<IStreamEvents>( | ||
ctx => new PullEventStream( | ||
ctx.GetService<IPullEventStreamEventStore>(), config)); | ||
|
||
var agent = ApertureAgentBuilder | ||
.CreateDefault(); | ||
|
||
services.AddSingleton( | ||
ctx => | ||
{ | ||
foreach (var projection in ctx.GetServices<IProjectEvents>()) | ||
agent.AddProjection(projection); | ||
|
||
if (configure != null) | ||
agent = configure(agent); | ||
|
||
return agent | ||
.UseEventStream(ctx.GetService<IStreamEvents>()); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters