| | | 1 | | using AsyncResponse; |
| | | 2 | | using AsyncResponse.Channels.PostgreSQL; |
| | | 3 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 4 | | |
| | | 5 | | namespace Microsoft.Extensions.DependencyInjection; |
| | | 6 | | |
| | | 7 | | /// <summary>DI registration for the PostgreSQL-backed AsyncResponse channel package.</summary> |
| | | 8 | | public static class PostgreSqlAsyncResponseChannelServiceCollectionExtensions |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Registers PostgreSQL <c>LISTEN/NOTIFY</c> as the response channel — behind |
| | | 12 | | /// <see cref="IAsyncResponsePublisher"/>, <see cref="IAsyncResponseSubscriber"/>, and |
| | | 13 | | /// <see cref="IRecoverableAsyncResponseSubscriber"/> — together with the durable PostgreSQL |
| | | 14 | | /// recovery-state store. The host must register a shared <see cref="Npgsql.NpgsqlDataSource"/> |
| | | 15 | | /// singleton, typically from the application's existing PostgreSQL connection string. |
| | | 16 | | /// </summary> |
| | | 17 | | public static AsyncResponseRegistrationBuilder WithPostgreSqlChannel( |
| | | 18 | | this AsyncResponseRegistrationBuilder builder, |
| | | 19 | | Action<PostgreSqlAsyncResponseChannelOptions>? configure = null) |
| | | 20 | | { |
| | 3 | 21 | | var services = builder.Services; |
| | 3 | 22 | | services.AddOptions(); |
| | 3 | 23 | | if (configure is not null) |
| | 3 | 24 | | services.Configure(configure); |
| | | 25 | | |
| | 3 | 26 | | services.TryAddSingleton<PostgreSqlChannelSql>(); |
| | | 27 | | |
| | 3 | 28 | | services.TryAddSingleton<PostgreSqlRecoveryStateStore>(); |
| | 3 | 29 | | services.Replace(ServiceDescriptor.Singleton<IRecoveryStateStore>(provider => provider.GetRequiredService<Postgr |
| | 3 | 30 | | services.Replace(ServiceDescriptor.Singleton<IRecoveryStateScanner>(provider => provider.GetRequiredService<Post |
| | | 31 | | |
| | 3 | 32 | | services.TryAddSingleton<PostgreSqlAsyncResponseChannel>(); |
| | 3 | 33 | | services.Replace(ServiceDescriptor.Singleton<IAsyncResponsePublisher>(provider => provider.GetRequiredService<Po |
| | 3 | 34 | | services.Replace(ServiceDescriptor.Singleton<IRawAsyncResponsePublisher>(provider => provider.GetRequiredService |
| | 3 | 35 | | services.Replace(ServiceDescriptor.Singleton<IAsyncResponseSubscriber>(provider => provider.GetRequiredService<P |
| | 3 | 36 | | services.Replace(ServiceDescriptor.Singleton<IRecoverableAsyncResponseSubscriber>(provider => provider.GetRequir |
| | 3 | 37 | | services.Replace(ServiceDescriptor.Singleton<IActiveSubscriberProbe>(provider => provider.GetRequiredService<Pos |
| | | 38 | | |
| | 3 | 39 | | services.Replace(ServiceDescriptor.Singleton<IRecoverableAsyncResponseBuilder>(provider => new RecoverableAsyncR |
| | 3 | 40 | | provider.GetRequiredService<IRecoverableAsyncResponseSubscriber>(), |
| | 3 | 41 | | provider.GetService<IWorkerTransport>(), |
| | 3 | 42 | | provider.GetService<IAsyncResponseReplyTargetProvider>(), |
| | 3 | 43 | | provider.GetRequiredService<AsyncResponseContextPropagation>()))); |
| | 3 | 44 | | services.Replace(ServiceDescriptor.Singleton<IAsyncResponseBuilder>(provider => provider.GetRequiredService<IRec |
| | | 45 | | |
| | 3 | 46 | | services.AddSingleton(new AsyncResponseChannelMarker(PostgreSqlAsyncResponseChannelOptions.ChannelName)); |
| | 3 | 47 | | return builder; |
| | | 48 | | } |
| | | 49 | | } |