diff --git a/docs/persistence.md b/docs/persistence.md index 2452c60..f83dd5a 100644 --- a/docs/persistence.md +++ b/docs/persistence.md @@ -8,7 +8,7 @@ `Itmo.Dev.Platform.Persistence.Postgres` с реализациями для БД Postgres. Для регистрации в DI-контейнере необходимо вызвать метод `AddPlatformPersistence`, предварительно зарегистрировав саму -платформу (метод `AddPlatform`). +платформу (метод `AddPlatform`, в нём необходимо выбрать сериализатор). Метод принимает делегат, в котором происходит конфигурация Persistence слоя. ```csharp diff --git a/src/Itmo.Dev.Platform.BackgroundTasks.Postgres/Migrations/BackgroundTasksMigrationPlatformInitializer.cs b/src/Itmo.Dev.Platform.BackgroundTasks.Postgres/Migrations/BackgroundTasksMigrationPlatformInitializer.cs index 4e63042..d103eb4 100644 --- a/src/Itmo.Dev.Platform.BackgroundTasks.Postgres/Migrations/BackgroundTasksMigrationPlatformInitializer.cs +++ b/src/Itmo.Dev.Platform.BackgroundTasks.Postgres/Migrations/BackgroundTasksMigrationPlatformInitializer.cs @@ -33,7 +33,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) .AddOptions() .Configure(o => persistenceOptions.Value.ApplyTo(o)); - collection.AddPlatform(); + collection.AddPlatform(config => config.WithSystemTextJsonConfiguration()); collection.AddPlatformPersistence( persistence => persistence.UsePostgres( diff --git a/src/Itmo.Dev.Platform.BackgroundTasks.Postgres/Repositories/BackgroundTaskRepository.cs b/src/Itmo.Dev.Platform.BackgroundTasks.Postgres/Repositories/BackgroundTaskRepository.cs index 301ea8d..497e837 100644 --- a/src/Itmo.Dev.Platform.BackgroundTasks.Postgres/Repositories/BackgroundTaskRepository.cs +++ b/src/Itmo.Dev.Platform.BackgroundTasks.Postgres/Repositories/BackgroundTaskRepository.cs @@ -7,9 +7,9 @@ using Itmo.Dev.Platform.BackgroundTasks.Tasks.Metadata; using Itmo.Dev.Platform.BackgroundTasks.Tasks.Results; using Itmo.Dev.Platform.Common.Models; +using Itmo.Dev.Platform.Common.Serialization; using Itmo.Dev.Platform.Persistence.Abstractions.Connections; using Itmo.Dev.Platform.Persistence.Postgres.Extensions; -using Newtonsoft.Json; using System.Data; using System.Runtime.CompilerServices; @@ -18,20 +18,20 @@ namespace Itmo.Dev.Platform.BackgroundTasks.Postgres.Repositories; internal class BackgroundTaskRepository : IBackgroundTaskInfrastructureRepository { private readonly BackgroundTaskQueryStorage _queryStorage; - private readonly JsonSerializerSettings _serializerSettings; private readonly IBackgroundTaskRegistry _backgroundTaskRegistry; private readonly IPersistenceConnectionProvider _connectionProvider; + private readonly IPlatformSerializer _serializer; public BackgroundTaskRepository( BackgroundTaskQueryStorage queryStorage, IPersistenceConnectionProvider connectionProvider, - JsonSerializerSettings serializerSettings, - IBackgroundTaskRegistry backgroundTaskRegistry) + IBackgroundTaskRegistry backgroundTaskRegistry, + IPlatformSerializer serializer) { _queryStorage = queryStorage; _connectionProvider = connectionProvider; - _serializerSettings = serializerSettings; _backgroundTaskRegistry = backgroundTaskRegistry; + _serializer = serializer; } public async IAsyncEnumerable QueryAsync( @@ -48,8 +48,8 @@ public async IAsyncEnumerable QueryAsync( .AddParameter("ids", query.Ids.Select(x => x.Value).ToArray()) .AddParameter("names", query.Names) .AddParameter("states", query.States) - .AddJsonArrayParameter("metadata", query.Metadatas, _serializerSettings) - .AddJsonArrayParameter("execution_metadata", query.ExecutionMetadatas, _serializerSettings) + .AddJsonArrayParameter("metadata", query.Metadatas) + .AddJsonArrayParameter("execution_metadata", query.ExecutionMetadatas) .AddParameter("cursor", query.Cursor) .AddParameter("max_scheduled_at", query.MaxScheduledAt) .AddParameter("page_size", query.PageSize ?? int.MaxValue); @@ -99,7 +99,7 @@ public async IAsyncEnumerable SearchIdsAsync( .AddParameter("ids", query.Ids.Select(x => x.Value).ToArray()) .AddParameter("names", query.Names) .AddParameter("states", query.States) - .AddJsonArrayParameter("metadata", query.Metadatas, _serializerSettings) + .AddJsonArrayParameter("metadata", query.Metadatas) .AddParameter("max_scheduled_at", query.MaxScheduledAt) .AddParameter("cursor", query.Cursor) .AddParameter("page_size", query.PageSize ?? int.MaxValue); @@ -123,8 +123,8 @@ public async IAsyncEnumerable AddRangeAsync( .AddParameter("types", tasks.Select(x => x.Type.AssemblyQualifiedName).ToArray()) .AddParameter("scheduled_at", tasks.Select(x => x.ScheduledAt)) .AddParameter("created_at", tasks.Select(x => x.CreatedAt).ToArray()) - .AddJsonArrayParameter("metadata", tasks.Select(x => x.Metadata), _serializerSettings) - .AddJsonArrayParameter("execution_metadata", tasks.Select(x => x.ExecutionMetadata), _serializerSettings); + .AddJsonArrayParameter("metadata", tasks.Select(x => x.Metadata)) + .AddJsonArrayParameter("execution_metadata", tasks.Select(x => x.ExecutionMetadata)); await using var reader = await command.ExecuteReaderAsync(cancellationToken); @@ -156,9 +156,9 @@ public async Task UpdateAsync(BackgroundTask backgroundTask, CancellationToken c .AddParameter("id", backgroundTask.Id.Value) .AddParameter("state", backgroundTask.State) .AddParameter("retry_number", backgroundTask.RetryNumber) - .AddJsonParameter("execution_metadata", backgroundTask.ExecutionMetadata, _serializerSettings) - .AddNullableJsonParameter("result", backgroundTask.Result, _serializerSettings) - .AddNullableJsonParameter("error", backgroundTask.Error, _serializerSettings) + .AddJsonParameter("execution_metadata", backgroundTask.ExecutionMetadata) + .AddNullableJsonParameter("result", backgroundTask.Result) + .AddNullableJsonParameter("error", backgroundTask.Error) .AddParameter("scheduled_at", backgroundTask.ScheduledAt); await command.ExecuteNonQueryAsync(cancellationToken); @@ -170,6 +170,6 @@ public async Task UpdateAsync(BackgroundTask backgroundTask, CancellationToken c if (value is null) return null; - return JsonConvert.DeserializeObject(value, type, _serializerSettings) as T; + return _serializer.Deserialize(value, type); } } diff --git a/src/Itmo.Dev.Platform.Common/Configurations/IPlatformCommonBuilder.cs b/src/Itmo.Dev.Platform.Common/Configurations/IPlatformCommonBuilder.cs new file mode 100644 index 0000000..500ee64 --- /dev/null +++ b/src/Itmo.Dev.Platform.Common/Configurations/IPlatformCommonBuilder.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; +using System.Text.Json; + +namespace Itmo.Dev.Platform.Common.Configurations; + +public static partial class PlatformCommonConfiguration +{ + public interface ISerializerStep + { + IFinalStep WithNewtonsoftSerialization(Action? configure = null); + + IFinalStep WithSystemTextJsonConfiguration(Action? configure = null); + } + + public interface IFinalStep; +} diff --git a/src/Itmo.Dev.Platform.Common/Configurations/PlatformCommonBuilder.cs b/src/Itmo.Dev.Platform.Common/Configurations/PlatformCommonBuilder.cs new file mode 100644 index 0000000..4f476dc --- /dev/null +++ b/src/Itmo.Dev.Platform.Common/Configurations/PlatformCommonBuilder.cs @@ -0,0 +1,37 @@ +using Itmo.Dev.Platform.Common.Serialization; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using System.Text.Json; +using static Itmo.Dev.Platform.Common.Configurations.PlatformCommonConfiguration; + +namespace Itmo.Dev.Platform.Common.Configurations; + +internal sealed class PlatformCommonBuilder(IServiceCollection collection) : ISerializerStep, IFinalStep +{ + public IFinalStep WithNewtonsoftSerialization(Action? configure = null) + { + collection.AddSingleton(); + collection.AddSingleton(sp => sp.GetRequiredService>().Value); + + var optionsBuilder = collection.AddOptions(); + + if (configure is not null) + optionsBuilder.Configure(configure); + + return this; + } + + public IFinalStep WithSystemTextJsonConfiguration(Action? configure = null) + { + collection.AddSingleton(); + collection.AddSingleton(sp => sp.GetRequiredService>().Value); + + var optionsBuilder = collection.AddOptions(); + + if (configure is not null) + optionsBuilder.Configure(configure); + + return this; + } +} diff --git a/src/Itmo.Dev.Platform.Common/Extensions/ServiceCollectionExtensions.cs b/src/Itmo.Dev.Platform.Common/Extensions/ServiceCollectionExtensions.cs index 17ebda7..edee3d9 100644 --- a/src/Itmo.Dev.Platform.Common/Extensions/ServiceCollectionExtensions.cs +++ b/src/Itmo.Dev.Platform.Common/Extensions/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using Itmo.Dev.Platform.Common.Configurations; using Itmo.Dev.Platform.Common.DateTime; using Itmo.Dev.Platform.Common.Lifetime.Extensions; using Itmo.Dev.Platform.Common.Options; @@ -11,9 +12,12 @@ namespace Itmo.Dev.Platform.Common.Extensions; public static class ServiceCollectionExtensions { - public static IServiceCollection AddPlatform(this IServiceCollection collection) + public static IServiceCollection AddPlatform( + this IServiceCollection collection, + Func configuration) { collection.AddPlatformLifetimes(); + collection.AddUtcDateTimeProvider(); collection .AddOptions() @@ -28,12 +32,18 @@ public static IServiceCollection AddPlatform(this IServiceCollection collection) collection.RemoveAll(typeof(IOptionsFactory<>)); collection.AddTransient(typeof(IOptionsFactory<>), typeof(PlatformOptionsFactory<>)); - + + var configurator = new PlatformCommonBuilder(collection); + configuration(configurator); + return collection; } public static IServiceCollection AddUtcDateTimeProvider(this IServiceCollection collection) - => collection.AddSingleton(); + { + collection.TryAddSingleton(); + return collection; + } internal static IServiceCollection AddHostedServiceUnsafe( this IServiceCollection collection, diff --git a/src/Itmo.Dev.Platform.Common/Itmo.Dev.Platform.Common.csproj b/src/Itmo.Dev.Platform.Common/Itmo.Dev.Platform.Common.csproj index 83b3b69..056e1fd 100644 --- a/src/Itmo.Dev.Platform.Common/Itmo.Dev.Platform.Common.csproj +++ b/src/Itmo.Dev.Platform.Common/Itmo.Dev.Platform.Common.csproj @@ -30,6 +30,7 @@ + diff --git a/src/Itmo.Dev.Platform.Common/Serialization/IPlatformSerializer.cs b/src/Itmo.Dev.Platform.Common/Serialization/IPlatformSerializer.cs new file mode 100644 index 0000000..fc75732 --- /dev/null +++ b/src/Itmo.Dev.Platform.Common/Serialization/IPlatformSerializer.cs @@ -0,0 +1,13 @@ +namespace Itmo.Dev.Platform.Common.Serialization; + +public interface IPlatformSerializer +{ + string Serialize(T value); + + string Serialize(T value, Type type); + + T? Deserialize(string value); + + T? Deserialize(string value, Type type) + where T : class; +} diff --git a/src/Itmo.Dev.Platform.Common/Serialization/NewtonsoftSerializer.cs b/src/Itmo.Dev.Platform.Common/Serialization/NewtonsoftSerializer.cs new file mode 100644 index 0000000..d99b4a3 --- /dev/null +++ b/src/Itmo.Dev.Platform.Common/Serialization/NewtonsoftSerializer.cs @@ -0,0 +1,29 @@ +using Microsoft.Extensions.Options; +using Newtonsoft.Json; + +namespace Itmo.Dev.Platform.Common.Serialization; + +internal sealed class NewtonsoftSerializer : IPlatformSerializer +{ + private readonly IOptions _options; + + public NewtonsoftSerializer(IOptions options) + { + _options = options; + } + + public string Serialize(T value) + => JsonConvert.SerializeObject(value, _options.Value); + + public string Serialize(T value, Type type) + => JsonConvert.SerializeObject(value, type, _options.Value); + + public T? Deserialize(string value) + => JsonConvert.DeserializeObject(value, _options.Value); + + public T? Deserialize(string value, Type type) + where T : class + { + return JsonConvert.DeserializeObject(value, type, _options.Value) as T; + } +} diff --git a/src/Itmo.Dev.Platform.Common/Serialization/SystemTextJsonSerializer.cs b/src/Itmo.Dev.Platform.Common/Serialization/SystemTextJsonSerializer.cs new file mode 100644 index 0000000..05a39ac --- /dev/null +++ b/src/Itmo.Dev.Platform.Common/Serialization/SystemTextJsonSerializer.cs @@ -0,0 +1,29 @@ +using Microsoft.Extensions.Options; +using System.Text.Json; + +namespace Itmo.Dev.Platform.Common.Serialization; + +internal sealed class SystemTextJsonSerializer : IPlatformSerializer +{ + private readonly IOptions _options; + + public SystemTextJsonSerializer(IOptions options) + { + _options = options; + } + + public string Serialize(T value) + => JsonSerializer.Serialize(value, _options.Value); + + public string Serialize(T value, Type type) + => JsonSerializer.Serialize(value, type, _options.Value); + + public T? Deserialize(string value) + => JsonSerializer.Deserialize(value, _options.Value); + + public T? Deserialize(string value, Type type) + where T : class + { + return JsonSerializer.Deserialize(value, type, _options.Value) as T; + } +} diff --git a/src/Itmo.Dev.Platform.MessagePersistence.Postgres/Migrations/MessagePersistenceMigrationPlatformInitializer.cs b/src/Itmo.Dev.Platform.MessagePersistence.Postgres/Migrations/MessagePersistenceMigrationPlatformInitializer.cs index b9ce6aa..cb9157c 100644 --- a/src/Itmo.Dev.Platform.MessagePersistence.Postgres/Migrations/MessagePersistenceMigrationPlatformInitializer.cs +++ b/src/Itmo.Dev.Platform.MessagePersistence.Postgres/Migrations/MessagePersistenceMigrationPlatformInitializer.cs @@ -35,7 +35,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) .AddOptions() .Configure(o => persistenceOptions.Value.ApplyTo(o)); - collection.AddPlatform(); + collection.AddPlatform(x => x.WithSystemTextJsonConfiguration()); collection.AddPlatformPersistence( persistence => persistence.UsePostgres( diff --git a/src/Itmo.Dev.Platform.Observability/WebApplicationBuilderExtensions.cs b/src/Itmo.Dev.Platform.Observability/WebApplicationBuilderExtensions.cs index f135309..4e71d14 100644 --- a/src/Itmo.Dev.Platform.Observability/WebApplicationBuilderExtensions.cs +++ b/src/Itmo.Dev.Platform.Observability/WebApplicationBuilderExtensions.cs @@ -27,7 +27,7 @@ public static void AddPlatformObservability( configuration.Invoke(configurator); } - collection.AddPlatform(); + collection.AddPlatform(x => x.WithSystemTextJsonConfiguration()); collection.AddLogging(x => x.AddConsole().SetMinimumLevel(LogLevel.Trace)); collection.AddSentryPlugins(); diff --git a/src/Itmo.Dev.Platform.Persistence.Abstractions/Commands/IPersistenceCommand.cs b/src/Itmo.Dev.Platform.Persistence.Abstractions/Commands/IPersistenceCommand.cs index d1185f5..81675e8 100644 --- a/src/Itmo.Dev.Platform.Persistence.Abstractions/Commands/IPersistenceCommand.cs +++ b/src/Itmo.Dev.Platform.Persistence.Abstractions/Commands/IPersistenceCommand.cs @@ -8,11 +8,11 @@ namespace Itmo.Dev.Platform.Persistence.Abstractions.Commands; public interface IPersistenceCommand : IAsyncDisposable { ValueTask ExecuteReaderAsync(CancellationToken cancellationToken); - + ValueTask ExecuteNonQueryAsync(CancellationToken cancellationToken); - + IPersistenceCommand AddParameter(DbParameter parameter); - + IPersistenceCommand AddParameter(string parameterName, T value); [OverloadResolutionPriority(int.MaxValue)] @@ -27,24 +27,12 @@ IPersistenceCommand AddMultiArrayStringParameter( string parameterName, IEnumerable> values); - IPersistenceCommand AddJsonParameter( - string parameterName, - T value, - JsonSerializerSettings? serializerSettings = null); + IPersistenceCommand AddJsonParameter(string parameterName, T value); - IPersistenceCommand AddNullableJsonParameter( - string parameterName, - T? value, - JsonSerializerSettings? serializerSettings = null) + IPersistenceCommand AddNullableJsonParameter(string parameterName, T? value) where T : class; - IPersistenceCommand AddJsonArrayParameter( - string parameterName, - IEnumerable values, - JsonSerializerSettings? serializerSettings = null); - - IPersistenceCommand AddJsonArrayParameter( - string parameterName, - IEnumerable values); + IPersistenceCommand AddJsonArrayParameter(string parameterName, IEnumerable values); -} \ No newline at end of file + IPersistenceCommand AddJsonArrayParameter(string parameterName, IEnumerable values); +} diff --git a/src/Itmo.Dev.Platform.Persistence.Postgres/Commands/PostgresPersistenceCommand.cs b/src/Itmo.Dev.Platform.Persistence.Postgres/Commands/PostgresPersistenceCommand.cs index c8e2fe3..5300476 100644 --- a/src/Itmo.Dev.Platform.Persistence.Postgres/Commands/PostgresPersistenceCommand.cs +++ b/src/Itmo.Dev.Platform.Persistence.Postgres/Commands/PostgresPersistenceCommand.cs @@ -1,6 +1,6 @@ +using Itmo.Dev.Platform.Common.Serialization; using Itmo.Dev.Platform.Persistence.Abstractions.Commands; using Itmo.Dev.Platform.Persistence.Postgres.Exceptions; -using Newtonsoft.Json; using Npgsql; using NpgsqlTypes; using System.Data.Common; @@ -13,10 +13,12 @@ namespace Itmo.Dev.Platform.Persistence.Postgres.Commands; internal class PostgresPersistenceCommand : IPersistenceCommand { private readonly NpgsqlCommand _command; + private readonly IPlatformSerializer _serializer; - public PostgresPersistenceCommand(NpgsqlCommand command) + public PostgresPersistenceCommand(NpgsqlCommand command, IPlatformSerializer serializer) { _command = command; + _serializer = serializer; } public async ValueTask ExecuteReaderAsync(CancellationToken cancellationToken) @@ -73,12 +75,9 @@ public IPersistenceCommand AddMultiArrayStringParameter( return this; } - public IPersistenceCommand AddJsonParameter( - string parameterName, - T value, - JsonSerializerSettings? serializerSettings = null) + public IPersistenceCommand AddJsonParameter(string parameterName, T value) { - var serialized = JsonConvert.SerializeObject(value, typeof(T), serializerSettings); + var serialized = _serializer.Serialize(value, typeof(T)); var parameter = new NpgsqlParameter(parameterName: parameterName, value: serialized) { @@ -89,14 +88,12 @@ public IPersistenceCommand AddJsonParameter( return this; } - public IPersistenceCommand AddNullableJsonParameter( - string parameterName, - T? value, - JsonSerializerSettings? serializerSettings = null) + public IPersistenceCommand AddNullableJsonParameter(string parameterName, T? value) where T : class { - object serialized = - value is null ? DBNull.Value : JsonConvert.SerializeObject(value, typeof(T), serializerSettings); + object serialized = value is null + ? DBNull.Value + : _serializer.Serialize(value, typeof(T)); var parameter = new NpgsqlParameter(parameterName: parameterName, value: serialized) { @@ -108,13 +105,10 @@ public IPersistenceCommand AddNullableJsonParameter( return this; } - public IPersistenceCommand AddJsonArrayParameter( - string parameterName, - IEnumerable values, - JsonSerializerSettings? serializerSettings = null) + public IPersistenceCommand AddJsonArrayParameter(string parameterName, IEnumerable values) { var serialized = values - .Select(value => JsonConvert.SerializeObject(value, typeof(T), serializerSettings)) + .Select(value => _serializer.Serialize(value, typeof(T))) .ToArray(); var parameter = new NpgsqlParameter(parameterName: parameterName, value: serialized) diff --git a/src/Itmo.Dev.Platform.Persistence.Postgres/Connections/PostgresPersistenceConnection.cs b/src/Itmo.Dev.Platform.Persistence.Postgres/Connections/PostgresPersistenceConnection.cs index 151fc8e..170f68b 100644 --- a/src/Itmo.Dev.Platform.Persistence.Postgres/Connections/PostgresPersistenceConnection.cs +++ b/src/Itmo.Dev.Platform.Persistence.Postgres/Connections/PostgresPersistenceConnection.cs @@ -1,3 +1,4 @@ +using Itmo.Dev.Platform.Common.Serialization; using Itmo.Dev.Platform.Persistence.Abstractions.Commands; using Itmo.Dev.Platform.Persistence.Abstractions.Connections; using Itmo.Dev.Platform.Persistence.Postgres.Commands; @@ -7,9 +8,12 @@ namespace Itmo.Dev.Platform.Persistence.Postgres.Connections; internal class PostgresPersistenceConnection : IPersistenceConnection { - public PostgresPersistenceConnection(NpgsqlConnection connection) + private readonly IPlatformSerializer _serializer; + + public PostgresPersistenceConnection(NpgsqlConnection connection, IPlatformSerializer serializer) { Connection = connection; + _serializer = serializer; } public NpgsqlConnection Connection { get; } @@ -17,7 +21,7 @@ public PostgresPersistenceConnection(NpgsqlConnection connection) public IPersistenceCommand CreateCommand(string query) { #pragma warning disable CA2100 - return new PostgresPersistenceCommand(new NpgsqlCommand(query, Connection)); + return new PostgresPersistenceCommand(new NpgsqlCommand(query, Connection), _serializer); #pragma warning restore CA2100 } @@ -25,4 +29,4 @@ public async ValueTask DisposeAsync() { await Connection.DisposeAsync(); } -} \ No newline at end of file +} diff --git a/src/Itmo.Dev.Platform.Persistence.Postgres/Connections/PostgresPersistenceConnectionProvider.cs b/src/Itmo.Dev.Platform.Persistence.Postgres/Connections/PostgresPersistenceConnectionProvider.cs index 622ad46..cca414f 100644 --- a/src/Itmo.Dev.Platform.Persistence.Postgres/Connections/PostgresPersistenceConnectionProvider.cs +++ b/src/Itmo.Dev.Platform.Persistence.Postgres/Connections/PostgresPersistenceConnectionProvider.cs @@ -1,3 +1,4 @@ +using Itmo.Dev.Platform.Common.Serialization; using Itmo.Dev.Platform.Persistence.Abstractions.Connections; using Npgsql; @@ -6,15 +7,17 @@ namespace Itmo.Dev.Platform.Persistence.Postgres.Connections; internal class PostgresPersistenceConnectionProvider : IPersistenceConnectionProvider { private readonly NpgsqlDataSource _dataSource; + private readonly IPlatformSerializer _serializer; - public PostgresPersistenceConnectionProvider(NpgsqlDataSource dataSource) + public PostgresPersistenceConnectionProvider(NpgsqlDataSource dataSource, IPlatformSerializer serializer) { _dataSource = dataSource; + _serializer = serializer; } public async ValueTask GetConnectionAsync(CancellationToken cancellationToken) { var connection = await _dataSource.OpenConnectionAsync(cancellationToken); - return new PostgresPersistenceConnection(connection); + return new PostgresPersistenceConnection(connection, _serializer); } -} \ No newline at end of file +} diff --git a/tests/Itmo.Dev.Platform.BackgroundTasks.Tests.Startup/Program.cs b/tests/Itmo.Dev.Platform.BackgroundTasks.Tests.Startup/Program.cs index e2b3dcc..d264901 100644 --- a/tests/Itmo.Dev.Platform.BackgroundTasks.Tests.Startup/Program.cs +++ b/tests/Itmo.Dev.Platform.BackgroundTasks.Tests.Startup/Program.cs @@ -3,16 +3,11 @@ var builder = WebApplication.CreateBuilder(args); -builder.Services.AddUtcDateTimeProvider(); -builder.Services.AddSingleton(new JsonSerializerSettings -{ - TypeNameHandling = TypeNameHandling.Auto, -}); - -builder.Services.AddPlatform(); +builder.Services.AddPlatform(x => x + .WithNewtonsoftSerialization(options => options.TypeNameHandling = TypeNameHandling.Auto)); var app = builder.Build(); app.Run(); -public partial class Program; \ No newline at end of file +public partial class Program; diff --git a/tests/Itmo.Dev.Platform.BackgroundTasks.Tests/Fixtures/BackgroundTasksDatabaseFixture.cs b/tests/Itmo.Dev.Platform.BackgroundTasks.Tests/Fixtures/BackgroundTasksDatabaseFixture.cs index 595822a..58b50d6 100644 --- a/tests/Itmo.Dev.Platform.BackgroundTasks.Tests/Fixtures/BackgroundTasksDatabaseFixture.cs +++ b/tests/Itmo.Dev.Platform.BackgroundTasks.Tests/Fixtures/BackgroundTasksDatabaseFixture.cs @@ -49,7 +49,7 @@ protected override void ConfigureServices(IServiceCollection collection) collection.AddSingleton(configuration); - collection.AddPlatform(); + collection.AddPlatform(x => x.WithNewtonsoftSerialization()); collection.AddPlatformPersistence( persistence => persistence.UsePostgres( diff --git a/tests/Itmo.Dev.Platform.Kafka.Tests.Startup/Program.cs b/tests/Itmo.Dev.Platform.Kafka.Tests.Startup/Program.cs index ae31526..578b329 100644 --- a/tests/Itmo.Dev.Platform.Kafka.Tests.Startup/Program.cs +++ b/tests/Itmo.Dev.Platform.Kafka.Tests.Startup/Program.cs @@ -16,14 +16,10 @@ builder.AddPlatformObservability(); builder.Services.AddOpenTelemetry().WithTracing(tracing => tracing.AddConsoleExporter()); -builder.Services.AddUtcDateTimeProvider(); -builder.Services.AddSingleton(new JsonSerializerSettings()); builder.Services.AddLogging(x => x.AddSerilog()); builder.Services.AddOptions(); -builder.Services.AddSingleton(p => p.GetRequiredService>().Value); - -builder.Services.AddPlatform(); +builder.Services.AddPlatform(x => x.WithNewtonsoftSerialization()); var app = builder.Build(); diff --git a/tests/Itmo.Dev.Platform.Kafka.Tests/Fixtures/KafkaDatabaseFixture.cs b/tests/Itmo.Dev.Platform.Kafka.Tests/Fixtures/KafkaDatabaseFixture.cs index 08d7760..e5fa10f 100644 --- a/tests/Itmo.Dev.Platform.Kafka.Tests/Fixtures/KafkaDatabaseFixture.cs +++ b/tests/Itmo.Dev.Platform.Kafka.Tests/Fixtures/KafkaDatabaseFixture.cs @@ -49,7 +49,7 @@ protected override void ConfigureServices(IServiceCollection collection) collection.AddSingleton(configuration); - collection.AddPlatform(); + collection.AddPlatform(x => x.WithNewtonsoftSerialization()); collection.AddPlatformPersistence( persistence => persistence.UsePostgres( diff --git a/tests/Itmo.Dev.Platform.MessagePersistence.Tests.Startup/Program.cs b/tests/Itmo.Dev.Platform.MessagePersistence.Tests.Startup/Program.cs index a9285cf..6cd7c81 100644 --- a/tests/Itmo.Dev.Platform.MessagePersistence.Tests.Startup/Program.cs +++ b/tests/Itmo.Dev.Platform.MessagePersistence.Tests.Startup/Program.cs @@ -6,7 +6,7 @@ builder.Services.AddUtcDateTimeProvider(); builder.Services.AddSingleton(new JsonSerializerSettings()); -builder.Services.AddPlatform(); +builder.Services.AddPlatform(x => x.WithNewtonsoftSerialization()); var app = builder.Build(); diff --git a/tests/Itmo.Dev.Platform.MessagePersistence.Tests/Fixtures/MessagePersistenceDatabaseFixture.cs b/tests/Itmo.Dev.Platform.MessagePersistence.Tests/Fixtures/MessagePersistenceDatabaseFixture.cs index 73b56cc..5f1baf8 100644 --- a/tests/Itmo.Dev.Platform.MessagePersistence.Tests/Fixtures/MessagePersistenceDatabaseFixture.cs +++ b/tests/Itmo.Dev.Platform.MessagePersistence.Tests/Fixtures/MessagePersistenceDatabaseFixture.cs @@ -49,7 +49,7 @@ protected override void ConfigureServices(IServiceCollection collection) collection.AddSingleton(configuration); - collection.AddPlatform(); + collection.AddPlatform(x => x.WithNewtonsoftSerialization()); collection.AddPlatformPersistence( persistence => persistence.UsePostgres( diff --git a/tests/Itmo.Dev.Platform.Persistence.Postgres.Tests/Fixtures/PostgresDatabaseFixture.cs b/tests/Itmo.Dev.Platform.Persistence.Postgres.Tests/Fixtures/PostgresDatabaseFixture.cs index 6ae04e3..a9f6c88 100644 --- a/tests/Itmo.Dev.Platform.Persistence.Postgres.Tests/Fixtures/PostgresDatabaseFixture.cs +++ b/tests/Itmo.Dev.Platform.Persistence.Postgres.Tests/Fixtures/PostgresDatabaseFixture.cs @@ -30,7 +30,7 @@ protected override void ConfigureServices(IServiceCollection collection) collection.AddSingleton(configuration); - collection.AddPlatform(); + collection.AddPlatform(x => x.WithNewtonsoftSerialization()); collection.AddPlatformPersistence( persistence => persistence