Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build/tasks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ $projects = @(

"Sa.Partitional.PostgreSql",

"Sa.Outbox.Support",
"Sa.Outbox",
"Sa.Outbox.PostgreSql",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>add a PostgreSQL-based configuration source to IConfiguration</Description>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sa.Configuration/Sa.Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>extensions for Configuration</Description>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sa.Data.PostgreSql/Sa.Data.PostgreSql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>Simple client for Npqsql</Description>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sa.Data.S3/Sa.Data.S3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Title>Sa.Data.S3</Title>
<Description>Simple client for S3 (Sa.Data.S3)</Description>
<PackageTags>s3</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>File storage management</Description>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>File storage management in Pg</Description>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sa.HybridFileStorage.S3/Sa.HybridFileStorage.S3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>File storage management in S3</Description>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sa.HybridFileStorage/Sa.HybridFileStorage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>File storage management</Description>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sa.Media.FFmpeg/Sa.Media.FFmpeg.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>FFmpeg wrapper</Description>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Sa.Media/Sa.Media.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>0.6.0</Version>
<Version>0.7.0</Version>
<Description>Async and memory-efficient WAV file reader for .NET </Description>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Npgsql;
using Sa.Data.PostgreSql;
using Sa.Outbox.Delivery;
using Sa.Outbox.PostgreSql.SqlBuilder;

namespace Sa.Outbox.PostgreSql.Commands;
Expand Down
18 changes: 18 additions & 0 deletions src/Sa.Outbox.PostgreSql/Configuration/OutboxMessageSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Sa.Outbox.PostgreSql.Serialization;
using System.Text.Json;

namespace Sa.Outbox.PostgreSql.Configuration;

internal sealed class OutboxMessageSerializer : IOutboxMessageSerializer
{
#pragma warning disable IL2026
#pragma warning disable IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
public T? Deserialize<T>(Stream stream) => JsonSerializer.Deserialize<T>(stream);


public void Serialize<T>(Stream stream, T value) => JsonSerializer.Serialize(stream, value);
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code

public static OutboxMessageSerializer Instance { get; } = new();
}
59 changes: 29 additions & 30 deletions src/Sa.Outbox.PostgreSql/Configuration/PgOutboxConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Sa.Data.PostgreSql;
using Sa.Outbox.PostgreSql.Serialization;
Expand All @@ -8,40 +7,15 @@ namespace Sa.Outbox.PostgreSql.Configuration;

internal sealed class PgOutboxConfiguration(IServiceCollection services) : IPgOutboxConfiguration
{
private static readonly ConcurrentDictionary<
IServiceCollection, HashSet<Action<IServiceProvider, PgOutboxSettings>>> s_invokers = [];

public IPgOutboxConfiguration WithOutboxSettings(Action<IServiceProvider, PgOutboxSettings>? configure = null)
{
if (configure != null)
{
if (s_invokers.TryGetValue(services, out var invokers))
{
invokers.Add(configure);
}
else
{
s_invokers[services] = [configure];
}
services.AddSingleton(configure);
}

RegisterOutboxSettings();

services.TryAddSingleton<PgOutboxSettings>(sp =>
{
PgOutboxSettings settings = new();

if (s_invokers.TryGetValue(services, out var invokers))
{
foreach (Action<IServiceProvider, PgOutboxSettings> build in invokers)
build.Invoke(sp, settings);

s_invokers.Remove(services, out _);
}

return settings;
});

AddSettings();
return this;
}

Expand All @@ -53,18 +27,43 @@ public IPgOutboxConfiguration WithDataSource(Action<IPgDataSourceSettingsBuilder

public IPgOutboxConfiguration WithMessageSerializer(Func<IServiceProvider, IOutboxMessageSerializer> messageSerializerFactory)
{
services.RemoveAll<IOutboxMessageSerializer>();
services.TryAddSingleton<IOutboxMessageSerializer>(messageSerializerFactory);
return this;
}

public IPgOutboxConfiguration WithMessageSerializer<TService>(TService instance)
where TService : class, IOutboxMessageSerializer
{
services.RemoveAll<IOutboxMessageSerializer>();
services.TryAddSingleton<IOutboxMessageSerializer>(instance);
return this;
}

private void AddSettings()
internal IPgOutboxConfiguration WithDefaultSerializer()
{
services.TryAddSingleton<IOutboxMessageSerializer>(OutboxMessageSerializer.Instance);
return this;
}

private void RegisterOutboxSettings()
{
services.TryAddSingleton<PgOutboxSettings>(sp =>
{
PgOutboxSettings settings = new();

var configureActions = sp.GetServices<Action<IServiceProvider, PgOutboxSettings>>();

foreach (var configureAction in configureActions)
configureAction.Invoke(sp, settings);

return settings;
});

RegisterComponentSettings();
}

private void RegisterComponentSettings()
{
services.TryAddSingleton<PgOutboxTableSettings>(sp => sp.GetRequiredService<PgOutboxSettings>().TableSettings);
services.TryAddSingleton<PgOutboxMigrationSettings>(sp => sp.GetRequiredService<PgOutboxSettings>().MigrationSettings);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using Sa.Extensions;
using Sa.Extensions;
using Sa.Outbox.Delivery;
using System.Diagnostics.CodeAnalysis;

namespace Sa.Outbox.PostgreSql;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public string[] All() =>
$"{MsgCreatedAt} BIGINT NOT NULL DEFAULT 0",
$"{DeliveryId} BIGINT NOT NULL DEFAULT 0",
$"{DeliveryAttempt} INT NOT NULL DEFAULT 0",
$"{DeliveryStatusCode} INT NOT NULL DEFAULT {(int)Outbox.DeliveryStatusCode.Pending}",
$"{DeliveryStatusCode} INT NOT NULL DEFAULT {(int)Outbox.Delivery.DeliveryStatusCode.Pending}",
$"{DeliveryStatusMessage} TEXT NOT NULL DEFAULT ''",
$"{DeliveryCreatedAt} BIGINT NOT NULL DEFAULT 0",
$"{ErrorId} BIGINT NOT NULL DEFAULT 0",
Expand Down Expand Up @@ -160,7 +160,7 @@ public sealed class TableFields
public string[] All() =>
[
$"{DeliveryId} BIGSERIAL NOT NULL",
$"{DeliveryStatusCode} INT NOT NULL DEFAULT {(int)Outbox.DeliveryStatusCode.Pending}",
$"{DeliveryStatusCode} INT NOT NULL DEFAULT {(int)Outbox.Delivery.DeliveryStatusCode.Pending}",
$"{DeliveryStatusMessage} TEXT NOT NULL DEFAULT ''",
$"{MsgPayloadId} TEXT NOT NULL DEFAULT ''",
$"{TenantId} INT NOT NULL DEFAULT 0",
Expand Down
12 changes: 7 additions & 5 deletions src/Sa.Outbox.PostgreSql/Configuration/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ public static IServiceCollection AddPgOutboxSettings(
this IServiceCollection services,
Action<IPgOutboxConfiguration>? configure = null)
{
var cfg = new PgOutboxConfiguration(services);
configure?.Invoke(cfg);

cfg
var configuration = new PgOutboxConfiguration(services)
.WithDefaultSerializer()
.WithOutboxSettings()
.WithDataSource()
;
;

configure?.Invoke(configuration);



return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Sa.Outbox.Job;
using Sa.Outbox.Delivery.Job;
using Sa.Partitional.PostgreSql;
using Sa.Schedule;

Expand Down
2 changes: 1 addition & 1 deletion src/Sa.Outbox.PostgreSql/Interceptors/Setup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Sa.Outbox.Job;
using Sa.Outbox.Delivery.Job;

namespace Sa.Outbox.PostgreSql.Interceptors;

Expand Down
Loading