Subtask 1
- Fix release build error: serialization and deserialization requires a
JsonSerializerContext when trimming is enabled. These changes are mandatory in order to enable native AOT.
Proposed Solution (not tested)
// Users will need to specify the type to serialize or deserialize by applying
// JsonSerializableAttribute to the context class (here: ExampleModel).
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(ExampleModel))]
internal partial class SourceGenerationContext : JsonSerializerContext
{
}
- public static ReadOnlySpan<byte> Serialize<T>(T value) where T : class
+ public static ReadOnlySpan<byte> Serialize<T, U>(T value, U context) where T : class, U : JsonSerializerContext
{
var buffer = new ArrayBufferWriter<byte>();
using var writer = new Utf8JsonWriter(buffer);
- JsonSerializer.Serialize(writer, value);
+ JsonSerializer.Serialize(writer, value, typeof(T), context.Default);
return buffer.WrittenSpan;
}
<!-- Because System.Text.Json uses reflection by default, calling a basic serialization method can break Native AOT apps, -->
<JsonSerializerIsReflectionEnabledByDefault>false<JsonSerializerIsReflectionEnabledByDefault/>
Because this change in interface is not as intuitive as before, add a minimal working example in the doc strings of the interface.
Subtask 2
- Define
ISerializationService and add doc strings
- Implement
SerializationService
- Implement
AddSerializationService
- Publish a new version of
AdvancedSystems.Core.Abstractions
- Write unit tests for
SerializationService and AddSerializationService
Subtask 3
- Refactor
CachingService and use SerializationService instead
- Register
SerializationService in AddCachingService as scoped service
- Update unit tests (
CachingServiceFixture, CachingServiceTests)
Subtask 1
JsonSerializerContextwhen trimming is enabled. These changes are mandatory in order to enable native AOT.Proposed Solution (not tested)
Subtask 2
ISerializationServiceand add doc stringsSerializationServiceAddSerializationServiceAdvancedSystems.Core.AbstractionsSerializationServiceandAddSerializationServiceSubtask 3
CachingServiceand useSerializationServiceinsteadSerializationServiceinAddCachingServiceas scoped serviceCachingServiceFixture,CachingServiceTests)