diff --git a/Eventuous.slnx b/Eventuous.slnx
index 83e61f82a..c10e88858 100644
--- a/Eventuous.slnx
+++ b/Eventuous.slnx
@@ -52,6 +52,7 @@
+
diff --git a/docs/src/content/docs/next/persistence/serialisation.md b/docs/src/content/docs/next/persistence/serialisation.md
index 9ca3b2bc1..19fbf7eb6 100644
--- a/docs/src/content/docs/next/persistence/serialisation.md
+++ b/docs/src/content/docs/next/persistence/serialisation.md
@@ -92,29 +92,58 @@ With the source generator in place, calling `RegisterKnownEventTypes()` is typic
### Default serializer
-Eventuous provides a default serializer implementation, which uses `System.Text.Json`. You just need to register it in the `Startup` to make it available for the infrastructure components, like [aggregate store](../aggregate-store) and [subscriptions](../../subscriptions/subs-concept).
+Eventuous provides two built-in serializer implementations, both using `System.Text.Json`:
-Normally, you don't need to register or provide the serializer instance to any of the Eventuous classes that perform serialization and deserialization work. It's because they will use the default serializer instance instead.
+- **`DefaultStaticEventSerializer`** — uses a `JsonSerializerContext` for source-generated, AOT-compatible serialization. This is the recommended choice for new applications and is required for Native AOT.
+- **`DefaultEventSerializer`** — uses reflection-based serialization. Available in the `Eventuous.Serialization.Json.Dynamic` package.
-However, you can register the default serializer with different options, or a custom serializer instead:
+The `IEventSerializer` interface itself has no AOT restrictions, so custom serializer implementations work cleanly in AOT scenarios.
+
+#### AOT-compatible serializer (recommended)
+
+For AOT applications, use `DefaultStaticEventSerializer` with a `JsonSerializerContext`:
```csharp title="Program.cs"
-builder.Services.AddSingleton(
+// Define a JsonSerializerContext with your event types
+[JsonSerializable(typeof(RoomBooked))]
+[JsonSerializable(typeof(BookingPaid))]
+[JsonSerializable(typeof(BookingCancelled))]
+public partial class BookingSerializerContext : JsonSerializerContext;
+
+// Register at startup
+EventSerializer.SetDefault(
+ new DefaultStaticEventSerializer(BookingSerializerContext.Default)
+);
+```
+
+#### Reflection-based serializer
+
+For non-AOT applications, the `DefaultEventSerializer` from the `Eventuous.Serialization.Json.Dynamic` package provides a simpler setup that doesn't require a `JsonSerializerContext`:
+
+```csharp title="Program.cs"
+EventSerializer.SetDefault(
new DefaultEventSerializer(
new JsonSerializerOptions(JsonSerializerDefaults.Default)
)
);
```
-You might want to avoid registering the serializer and override the one that Eventuous uses as the default instance:
+:::caution
+`DefaultEventSerializer` uses reflection-based JSON serialization and is not compatible with Native AOT. If you plan to publish your application as AOT, use `DefaultStaticEventSerializer` instead.
+:::
+
+#### Configuring via DI
+
+You can also register the serializer in the DI container:
```csharp title="Program.cs"
-var defaultSerializer = new DefaultEventSerializer(
- new JsonSerializerOptions(JsonSerializerDefaults.Default)
+builder.Services.AddSingleton(
+ new DefaultStaticEventSerializer(BookingSerializerContext.Default)
);
-DefaultEventSerializer.SetDefaultSerializer(serializer);
```
+Infrastructure components like event stores, subscriptions, and producers will resolve `IEventSerializer` from DI when available. If no serializer is registered in DI, they fall back to `EventSerializer.Default`, which must be configured explicitly at startup.
+
### Metadata serializer
In many cases you might want to store event metadata in addition to the event payload. Normally, you'd use the same way to serialize both the event payload and its metadata, but it's not always the case. For example, you might store your events in Protobuf, but keep metadata as JSON.
diff --git a/samples/kurrentdb/Bookings/Bookings.csproj b/samples/kurrentdb/Bookings/Bookings.csproj
index 361244a4b..2d46cb2c6 100644
--- a/samples/kurrentdb/Bookings/Bookings.csproj
+++ b/samples/kurrentdb/Bookings/Bookings.csproj
@@ -35,6 +35,7 @@
+
diff --git a/samples/kurrentdb/Bookings/Program.cs b/samples/kurrentdb/Bookings/Program.cs
index ec51b0fd3..0060b1549 100644
--- a/samples/kurrentdb/Bookings/Program.cs
+++ b/samples/kurrentdb/Bookings/Program.cs
@@ -22,7 +22,7 @@
// .WriteTo.Seq("http://localhost:5341")
.CreateLogger();
-DefaultEventSerializer.SetDefaultSerializer(new DefaultStaticEventSerializer(new SourceGenerationContext()));
+EventSerializer.SetDefault(new DefaultStaticEventSerializer(new SourceGenerationContext()));
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
diff --git a/samples/kurrentdb/Bookings/Registrations.cs b/samples/kurrentdb/Bookings/Registrations.cs
index 5bc7d77c8..b778fdd9b 100644
--- a/samples/kurrentdb/Bookings/Registrations.cs
+++ b/samples/kurrentdb/Bookings/Registrations.cs
@@ -23,7 +23,7 @@ namespace Bookings;
public static class Registrations {
extension(IServiceCollection services) {
public void AddEventuous(IConfiguration configuration) {
- DefaultEventSerializer.SetDefaultSerializer(
+ EventSerializer.SetDefault(
new DefaultEventSerializer(new JsonSerializerOptions(JsonSerializerDefaults.Web).ConfigureForNodaTime(DateTimeZoneProviders.Tzdb))
);
diff --git a/samples/postgres/Bookings/Bookings.csproj b/samples/postgres/Bookings/Bookings.csproj
index 258c4d860..4ef641f59 100644
--- a/samples/postgres/Bookings/Bookings.csproj
+++ b/samples/postgres/Bookings/Bookings.csproj
@@ -31,5 +31,6 @@
+
\ No newline at end of file
diff --git a/samples/postgres/Bookings/Registrations.cs b/samples/postgres/Bookings/Registrations.cs
index 78a7040a9..ce1f6d3dd 100644
--- a/samples/postgres/Bookings/Registrations.cs
+++ b/samples/postgres/Bookings/Registrations.cs
@@ -19,7 +19,7 @@ namespace Bookings;
public static class Registrations {
public static void AddEventuous(this IServiceCollection services, IConfiguration configuration) {
- DefaultEventSerializer.SetDefaultSerializer(
+ EventSerializer.SetDefault(
new DefaultEventSerializer(new JsonSerializerOptions(JsonSerializerDefaults.Web).ConfigureForNodaTime(DateTimeZoneProviders.Tzdb))
);
diff --git a/src/Azure/src/Eventuous.Azure.ServiceBus/Producers/ServiceBusProducer.cs b/src/Azure/src/Eventuous.Azure.ServiceBus/Producers/ServiceBusProducer.cs
index bcd834291..e48000877 100644
--- a/src/Azure/src/Eventuous.Azure.ServiceBus/Producers/ServiceBusProducer.cs
+++ b/src/Azure/src/Eventuous.Azure.ServiceBus/Producers/ServiceBusProducer.cs
@@ -40,7 +40,7 @@ public ServiceBusProducer(
_options = options;
_log = log;
_sender = client.CreateSender(options.QueueOrTopicName, options.SenderOptions);
- _serializer = serializer ?? DefaultEventSerializer.Instance;
+ _serializer = serializer ?? EventSerializer.Default;
_messageBatchBuilder = new(_sender, this._serializer, options.AttributeNames, SetActivityMessageType);
log?.LogInformation("ServiceBusProducer created for {QueueOrTopicName}", options.QueueOrTopicName);
}
diff --git a/src/Azure/test/Eventuous.Tests.Azure.ServiceBus/ConvertEventToMessage.cs b/src/Azure/test/Eventuous.Tests.Azure.ServiceBus/ConvertEventToMessage.cs
index 9abd8e54a..a024e1da8 100644
--- a/src/Azure/test/Eventuous.Tests.Azure.ServiceBus/ConvertEventToMessage.cs
+++ b/src/Azure/test/Eventuous.Tests.Azure.ServiceBus/ConvertEventToMessage.cs
@@ -9,7 +9,7 @@ public class ConvertEventToMessage {
public ConvertEventToMessage() {
var builder = new ServiceBusMessageBuilder(
- DefaultEventSerializer.Instance,
+ EventSerializer.Default,
"test-stream",
new(),
new() {
@@ -92,7 +92,7 @@ public class WithMessagePropertiesInMetaData {
public WithMessagePropertiesInMetaData() {
var attributeNames = new ServiceBusMessageAttributeNames();
- var builder = new ServiceBusMessageBuilder(DefaultEventSerializer.Instance, "test-stream", attributeNames, new());
+ var builder = new ServiceBusMessageBuilder(EventSerializer.Default, "test-stream", attributeNames, new());
_message = builder.CreateServiceBusMessage(
new(
diff --git a/src/Azure/test/Eventuous.Tests.Azure.ServiceBus/TestSetup.cs b/src/Azure/test/Eventuous.Tests.Azure.ServiceBus/TestSetup.cs
new file mode 100644
index 000000000..65c9d9263
--- /dev/null
+++ b/src/Azure/test/Eventuous.Tests.Azure.ServiceBus/TestSetup.cs
@@ -0,0 +1,12 @@
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
+using System.Text.Json;
+
+namespace Eventuous.Tests.Azure.ServiceBus;
+
+static class TestSetup {
+ [ModuleInitializer]
+ [SuppressMessage("Usage", "CA2255")]
+ internal static void Initialize()
+ => EventSerializer.SetDefault(new DefaultEventSerializer(new(JsonSerializerDefaults.Web)));
+}
diff --git a/src/Core/src/Eventuous.Application/AggregateService/CommandService.cs b/src/Core/src/Eventuous.Application/AggregateService/CommandService.cs
index 45111b4de..a48c79e1d 100644
--- a/src/Core/src/Eventuous.Application/AggregateService/CommandService.cs
+++ b/src/Core/src/Eventuous.Application/AggregateService/CommandService.cs
@@ -59,8 +59,6 @@ protected IDefineExpectedState On()
/// Cancellation token
/// of the execution
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task> Handle(TCommand command, CancellationToken cancellationToken) where TCommand : class {
if (!_handlers.TryGet(out var registeredHandler)) {
Log.CommandHandlerNotFound();
diff --git a/src/Core/src/Eventuous.Application/Diagnostics/TracedCommandService.cs b/src/Core/src/Eventuous.Application/Diagnostics/TracedCommandService.cs
index be3c6c81d..8de58ca9b 100644
--- a/src/Core/src/Eventuous.Application/Diagnostics/TracedCommandService.cs
+++ b/src/Core/src/Eventuous.Application/Diagnostics/TracedCommandService.cs
@@ -18,8 +18,6 @@ namespace Eventuous.Diagnostics;
InnerService = appService;
}
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task> Handle(TCommand command, CancellationToken cancellationToken)
where TCommand : class
=> CommandServiceActivity.TryExecute(
diff --git a/src/Core/src/Eventuous.Application/FunctionalService/CommandService.cs b/src/Core/src/Eventuous.Application/FunctionalService/CommandService.cs
index 5563b2f2e..83f10e043 100644
--- a/src/Core/src/Eventuous.Application/FunctionalService/CommandService.cs
+++ b/src/Core/src/Eventuous.Application/FunctionalService/CommandService.cs
@@ -66,8 +66,6 @@ protected CommandService(IEventStore store, ITypeMapper? typeMap = null, AmendEv
/// Command type
/// instance
/// Throws when there's no command handler was registered for the command type
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task> Handle(TCommand command, CancellationToken cancellationToken) where TCommand : class {
if (!_handlers.TryGet(out var registeredHandler)) {
Log.CommandHandlerNotFound();
diff --git a/src/Core/src/Eventuous.Application/ICommandService.cs b/src/Core/src/Eventuous.Application/ICommandService.cs
index 132aa39df..b6b4fe241 100644
--- a/src/Core/src/Eventuous.Application/ICommandService.cs
+++ b/src/Core/src/Eventuous.Application/ICommandService.cs
@@ -6,8 +6,6 @@
namespace Eventuous;
public interface ICommandService where TState : State, new() {
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
Task> Handle(TCommand command, CancellationToken cancellationToken) where TCommand : class;
}
diff --git a/src/Core/src/Eventuous.Application/Persistence/WriterExtensions.cs b/src/Core/src/Eventuous.Application/Persistence/WriterExtensions.cs
index 88213674c..b7a80e87f 100644
--- a/src/Core/src/Eventuous.Application/Persistence/WriterExtensions.cs
+++ b/src/Core/src/Eventuous.Application/Persistence/WriterExtensions.cs
@@ -5,8 +5,6 @@ namespace Eventuous.Persistence;
static class WriterExtensions {
extension(IEventWriter writer) {
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task Store(ProposedAppend append, AmendEvent? amendEvent, CancellationToken cancellationToken) {
Ensure.NotNull(append.Events);
@@ -33,8 +31,6 @@ NewStreamEvent ToStreamEvent(ProposedEvent evt) {
}
}
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task Store(
IReadOnlyCollection appends,
AmendEvent? amendEvent,
diff --git a/src/Core/src/Eventuous.Application/ThrowingCommandService.cs b/src/Core/src/Eventuous.Application/ThrowingCommandService.cs
index 296e9e629..cc49091de 100644
--- a/src/Core/src/Eventuous.Application/ThrowingCommandService.cs
+++ b/src/Core/src/Eventuous.Application/ThrowingCommandService.cs
@@ -10,8 +10,6 @@ namespace Eventuous;
///
public class ThrowingCommandService(ICommandService inner) : ICommandService
where TState : State, new() {
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task> Handle(TCommand command, CancellationToken cancellationToken) where TCommand : class {
var result = await inner.Handle(command, cancellationToken);
diff --git a/src/Core/src/Eventuous.Persistence/AggregateStore/AggregatePersistenceExtensions.cs b/src/Core/src/Eventuous.Persistence/AggregateStore/AggregatePersistenceExtensions.cs
index 1907e364a..8f9c7cc14 100644
--- a/src/Core/src/Eventuous.Persistence/AggregateStore/AggregatePersistenceExtensions.cs
+++ b/src/Core/src/Eventuous.Persistence/AggregateStore/AggregatePersistenceExtensions.cs
@@ -20,8 +20,6 @@ public static class AggregatePersistenceExtensions {
/// Aggregate state type
/// Append event result
/// Gets thrown if the expected stream version mismatches with the given original stream version
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task StoreAggregate(
StreamName streamName,
TAggregate aggregate,
@@ -52,8 +50,6 @@ public async Task StoreAggregate(
/// Aggregate identity type
/// Append event result
/// Gets thrown if the expected stream version mismatches with the given original stream version
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task StoreAggregate(
TAggregate aggregate,
TId id,
@@ -84,8 +80,6 @@ public Task StoreAggregate(
/// Aggregate identity type
/// Append event result
/// Gets thrown if the expected stream version mismatches with the given original stream version
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task StoreAggregate(
TAggregate aggregate,
StreamNameMap? streamNameMap = null,
@@ -115,8 +109,6 @@ public Task StoreAggregate(
/// Aggregate instance
/// If failIfNotFound set to true, this exception is thrown if there's no stream
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task LoadAggregate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState>(
StreamName streamName,
bool failIfNotFound = true,
@@ -155,8 +147,6 @@ public Task StoreAggregate(
/// Aggregate instance
/// If failIfNotFound set to true, this exception is thrown if there's no stream
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task LoadAggregate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState, TId>(
TId aggregateId,
StreamNameMap? streamNameMap = null,
diff --git a/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStore.cs b/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStore.cs
index aeda1b036..3884b355b 100644
--- a/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStore.cs
+++ b/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStore.cs
@@ -32,23 +32,17 @@ public AggregateStore(
///
[Obsolete("Use IEventWriter.StoreAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task Store(StreamName streamName, TAggregate aggregate, CancellationToken cancellationToken)
where TAggregate : Aggregate where TState : State, new()
=> _eventWriter.StoreAggregate(streamName, aggregate, _amendEvent, cancellationToken);
///
[Obsolete("Use IEventReader.LoadAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task Load<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T, TState>(StreamName streamName, CancellationToken cancellationToken) where T : Aggregate where TState : State, new()
=> _eventReader.LoadAggregate(streamName, true, _factoryRegistry, cancellationToken);
///
[Obsolete("Use IEventReader.LoadAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task LoadOrNew<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T, TState>(StreamName streamName, CancellationToken cancellationToken)
where T : Aggregate where TState : State, new()
=> _eventReader.LoadAggregate(streamName, false, _factoryRegistry, cancellationToken);
diff --git a/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStoreExtensions.cs b/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStoreExtensions.cs
index 296b78582..3f8fbc152 100644
--- a/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStoreExtensions.cs
+++ b/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStoreExtensions.cs
@@ -17,8 +17,6 @@ public static class AggregateStoreExtensions {
/// Aggregate id type
///
[Obsolete("Use IEventReader.LoadAggregates instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task Load
<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T, TState, TId>(StreamNameMap streamNameMap, TId id, CancellationToken cancellationToken)
where T : Aggregate where TId : Id where TState : State, new() {
@@ -39,8 +37,6 @@ public async Task Load
/// Aggregate id type
///
[Obsolete("Use IEventReader.LoadAggregates instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task LoadOrNew<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState, TId>(
StreamNameMap streamNameMap,
TId id,
diff --git a/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStoreWithArchive.cs b/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStoreWithArchive.cs
index 52ae93beb..1e80ab7a6 100644
--- a/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStoreWithArchive.cs
+++ b/src/Core/src/Eventuous.Persistence/AggregateStore/AggregateStoreWithArchive.cs
@@ -15,22 +15,16 @@ public class AggregateStore(
readonly TieredEventStore _tieredEventStore = new(eventStore, archiveReader);
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task Store(StreamName streamName, TAggregate aggregate, CancellationToken cancellationToken)
where TAggregate : Aggregate where TState : State, new()
=> eventStore.StoreAggregate(streamName, aggregate, amendEvent, cancellationToken);
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task Load<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState>(StreamName streamName, CancellationToken cancellationToken)
where TAggregate : Aggregate where TState : State, new()
=> _tieredEventStore.LoadAggregate(streamName, true, _factoryRegistry, cancellationToken);
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task LoadOrNew<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState>(StreamName streamName, CancellationToken cancellationToken)
where TAggregate : Aggregate where TState : State, new()
=> _tieredEventStore.LoadAggregate(streamName, false, _factoryRegistry, cancellationToken);
diff --git a/src/Core/src/Eventuous.Persistence/AggregateStore/IAggregateStore.cs b/src/Core/src/Eventuous.Persistence/AggregateStore/IAggregateStore.cs
index a1eeeff67..df8631072 100644
--- a/src/Core/src/Eventuous.Persistence/AggregateStore/IAggregateStore.cs
+++ b/src/Core/src/Eventuous.Persistence/AggregateStore/IAggregateStore.cs
@@ -20,8 +20,6 @@ public interface IAggregateStore {
/// Aggregate state type
/// Result of the append operation
[Obsolete("Use IEventWriter.StoreAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task Store(TAggregate aggregate, TId id, CancellationToken cancellationToken)
where TAggregate : Aggregate where TId : Id where TState : State, new()
=> Store(StreamNameFactory.For(id), aggregate, cancellationToken);
@@ -36,8 +34,6 @@ public Task Store(TAggregate aggreg
/// Aggregate state type
/// Result of the append operation
[Obsolete("Use IEventWriter.StoreAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
Task Store(StreamName streamName, TAggregate aggregate, CancellationToken cancellationToken)
where TAggregate : Aggregate where TState : State, new();
@@ -51,8 +47,6 @@ Task Store(StreamName streamName, TAggre
/// Aggregate identity type
/// Aggregate instance
[Obsolete("Use IEventReader.LoadAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task Load<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState, TId>(TId id, CancellationToken cancellationToken)
where TAggregate : Aggregate where TId : Id where TState : State, new()
=> Load(StreamNameFactory.For(id), cancellationToken);
@@ -66,8 +60,6 @@ Task Store(StreamName streamName, TAggre
/// Aggregate state type
/// Aggregate instance
[Obsolete("Use IEventReader.LoadAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
Task Load<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState>(StreamName streamName, CancellationToken cancellationToken)
where TAggregate : Aggregate where TState : State, new();
@@ -82,8 +74,6 @@ Task Store(StreamName streamName, TAggre
/// Aggregate identity type
/// Aggregate instance
[Obsolete("Use IEventReader.LoadAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task LoadOrNew<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState, TId>(TId id, CancellationToken cancellationToken)
where TAggregate : Aggregate where TId : Id where TState : State, new()
=> LoadOrNew(StreamNameFactory.For(id), cancellationToken);
@@ -98,8 +88,6 @@ Task Store(StreamName streamName, TAggre
/// Aggregate state type
/// Aggregate instance
[Obsolete("Use IEventReader.LoadAggregate instead.")]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
Task LoadOrNew<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TAggregate, TState>(StreamName streamName, CancellationToken cancellationToken)
where TAggregate : Aggregate where TState : State, new();
}
diff --git a/src/Core/src/Eventuous.Persistence/Constants.cs b/src/Core/src/Eventuous.Persistence/Constants.cs
deleted file mode 100644
index 3f1af6160..000000000
--- a/src/Core/src/Eventuous.Persistence/Constants.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright (C) Eventuous HQ OÜ. All rights reserved
-// Licensed under the Apache License, Version 2.0.
-
-namespace Eventuous;
-
-internal static class AttrConstants {
- internal const string DynamicSerializationMessage = "Only works with AOT when using DefaultStaticEventSerializer";
-}
diff --git a/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventReader.cs b/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventReader.cs
index 1f37de407..f9b8048ff 100644
--- a/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventReader.cs
+++ b/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventReader.cs
@@ -14,13 +14,9 @@ public class TracedEventReader(IEventReader reader) : BaseTracer, IEventReader {
IEventReader Inner { get; } = reader;
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public IAsyncEnumerable ReadEvents(StreamName stream, StreamReadPosition start, int count, CancellationToken cancellationToken)
=> TraceEnumerable(stream, Operations.ReadEvents, Inner.ReadEvents(stream, start, count, cancellationToken));
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public IAsyncEnumerable ReadEventsBackwards(StreamName stream, StreamReadPosition start, int count, CancellationToken cancellationToken)
=> TraceEnumerable(stream, Operations.ReadEvents, Inner.ReadEventsBackwards(stream, start, count, cancellationToken));
diff --git a/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventStore.cs b/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventStore.cs
index 0ed2fe8ea..4b0ab156c 100644
--- a/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventStore.cs
+++ b/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventStore.cs
@@ -20,8 +20,6 @@ public class TracedEventStore(IEventStore eventStore) : BaseTracer, IEventStore
public Task StreamExists(StreamName stream, CancellationToken cancellationToken)
=> Trace(stream, Operations.StreamExists, () => Inner.StreamExists(stream, cancellationToken));
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task AppendEvents(
StreamName stream,
ExpectedStreamVersion expectedVersion,
@@ -30,18 +28,12 @@ CancellationToken cancellationToken
)
=> Writer.AppendEvents(stream, expectedVersion, events, cancellationToken);
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public Task AppendEvents(IReadOnlyCollection appends, CancellationToken cancellationToken)
=> Writer.AppendEvents(appends, cancellationToken);
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public IAsyncEnumerable ReadEvents(StreamName stream, StreamReadPosition start, int count, CancellationToken cancellationToken)
=> Reader.ReadEvents(stream, start, count, cancellationToken);
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public IAsyncEnumerable ReadEventsBackwards(StreamName stream, StreamReadPosition start, int count, CancellationToken cancellationToken)
=> Reader.ReadEventsBackwards(stream, start, count, cancellationToken);
diff --git a/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventWriter.cs b/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventWriter.cs
index 1df507c52..1c95d69a6 100644
--- a/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventWriter.cs
+++ b/src/Core/src/Eventuous.Persistence/Diagnostics/Tracing/TracedEventWriter.cs
@@ -13,8 +13,6 @@ public class TracedEventWriter(IEventWriter writer) : BaseTracer, IEventWriter {
readonly string _componentName = writer.GetType().Name;
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task AppendEvents(
StreamName stream,
ExpectedStreamVersion expectedVersion,
@@ -42,8 +40,6 @@ CancellationToken cancellationToken
}
}
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task AppendEvents(IReadOnlyCollection appends, CancellationToken cancellationToken) {
if (appends.Count == 0) return [];
diff --git a/src/Core/src/Eventuous.Persistence/EventStore/IEventReader.cs b/src/Core/src/Eventuous.Persistence/EventStore/IEventReader.cs
index c419dc194..8268287b9 100644
--- a/src/Core/src/Eventuous.Persistence/EventStore/IEventReader.cs
+++ b/src/Core/src/Eventuous.Persistence/EventStore/IEventReader.cs
@@ -13,8 +13,6 @@ public interface IEventReader {
/// How many events to read
/// Cancellation token
/// An async enumerable of events retrieved from the stream
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
IAsyncEnumerable ReadEvents(StreamName stream, StreamReadPosition start, int count, CancellationToken cancellationToken);
///
@@ -26,7 +24,5 @@ public interface IEventReader {
/// How many events to read
/// Cancellation token
/// An async enumerable of events retrieved from the stream
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
IAsyncEnumerable ReadEventsBackwards(StreamName stream, StreamReadPosition start, int count, CancellationToken cancellationToken);
}
diff --git a/src/Core/src/Eventuous.Persistence/EventStore/IEventWriter.cs b/src/Core/src/Eventuous.Persistence/EventStore/IEventWriter.cs
index cef4b6d2b..490f3568a 100644
--- a/src/Core/src/Eventuous.Persistence/EventStore/IEventWriter.cs
+++ b/src/Core/src/Eventuous.Persistence/EventStore/IEventWriter.cs
@@ -13,8 +13,6 @@ public interface IEventWriter {
/// Cancellation token
/// Append result, which contains the global position of the last written event,
/// as well as the next stream version
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
Task AppendEvents(
StreamName stream,
ExpectedStreamVersion expectedVersion,
@@ -30,8 +28,6 @@ CancellationToken cancellationToken
/// Collection of stream appends to perform
/// Cancellation token
/// Array of append results, one per stream in the same order as input
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
async Task AppendEvents(IReadOnlyCollection appends, CancellationToken cancellationToken) {
var results = new AppendEventsResult[appends.Count];
var i = 0;
diff --git a/src/Core/src/Eventuous.Persistence/EventStore/StoreFunctions.cs b/src/Core/src/Eventuous.Persistence/EventStore/StoreFunctions.cs
index 4f59d9344..35d8e9689 100644
--- a/src/Core/src/Eventuous.Persistence/EventStore/StoreFunctions.cs
+++ b/src/Core/src/Eventuous.Persistence/EventStore/StoreFunctions.cs
@@ -17,8 +17,6 @@ public static class StoreFunctions {
/// Append events result
/// Any exception that occurred in the event store
/// Gets thrown if the expected stream version mismatches with the given original stream version
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task Store(
StreamName streamName,
ExpectedStreamVersion expectedStreamVersion,
@@ -53,8 +51,6 @@ NewStreamEvent ToStreamEvent(object evt) {
}
}
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
public async Task Store(
IReadOnlyCollection<(StreamName StreamName, ExpectedStreamVersion ExpectedVersion, IReadOnlyCollection
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
protected override async ValueTask Subscribe(CancellationToken cancellationToken) {
var filterOptions = new SubscriptionFilterOptions(
Options.EventFilter ?? EventTypeFilter.ExcludeSystemEvents(),
@@ -112,8 +110,6 @@ void HandleDrop(global::KurrentDB.Client.StreamSubscription _, SubscriptionDropp
=> Dropped(KurrentDBMappings.AsDropReason(reason), ex);
}
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
MessageConsumeContext CreateContext(ResolvedEvent re, CancellationToken cancellationToken) {
var evt = DeserializeData(
re.Event.ContentType,
diff --git a/src/KurrentDB/src/Eventuous.KurrentDB/Subscriptions/PersistentSubscriptionBase.cs b/src/KurrentDB/src/Eventuous.KurrentDB/Subscriptions/PersistentSubscriptionBase.cs
index 691080504..6dc68865a 100644
--- a/src/KurrentDB/src/Eventuous.KurrentDB/Subscriptions/PersistentSubscriptionBase.cs
+++ b/src/KurrentDB/src/Eventuous.KurrentDB/Subscriptions/PersistentSubscriptionBase.cs
@@ -116,8 +116,6 @@ protected PersistentSubscriptionBase(
/// Subscribe to a persistent subscription
///
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
protected override async ValueTask Subscribe(CancellationToken cancellationToken) {
var settings = Options.SubscriptionSettings ?? new PersistentSubscriptionSettings(Options.ResolveLinkTos);
@@ -194,8 +192,6 @@ async ValueTask Nack(MessageConsumeContext ctx, Exception exception) {
await _handleEventProcessingFailure(Client, subscription, re, exception).NoContext();
}
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
MessageConsumeContext CreateContext(ResolvedEvent re, CancellationToken cancellationToken) {
var evt = DeserializeData(
re.Event.ContentType,
diff --git a/src/KurrentDB/src/Eventuous.KurrentDB/Subscriptions/StreamSubscription.cs b/src/KurrentDB/src/Eventuous.KurrentDB/Subscriptions/StreamSubscription.cs
index d9029e823..9254e5e4b 100644
--- a/src/KurrentDB/src/Eventuous.KurrentDB/Subscriptions/StreamSubscription.cs
+++ b/src/KurrentDB/src/Eventuous.KurrentDB/Subscriptions/StreamSubscription.cs
@@ -86,8 +86,6 @@ public StreamSubscription(
/// Starts a catch-up subscription
///
///
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
protected override async ValueTask Subscribe(CancellationToken cancellationToken) {
var (_, position) = await GetCheckpoint(cancellationToken).NoContext();
@@ -128,8 +126,6 @@ void HandleDrop(global::KurrentDB.Client.StreamSubscription _, SubscriptionDropp
=> Dropped(KurrentDBMappings.AsDropReason(reason), ex);
}
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
MessageConsumeContext CreateContext(ResolvedEvent re, CancellationToken cancellationToken) {
var evt = DeserializeData(
re.Event.ContentType,
diff --git a/src/KurrentDB/test/Eventuous.Tests.KurrentDB/Subscriptions/CustomDependenciesTests.cs b/src/KurrentDB/test/Eventuous.Tests.KurrentDB/Subscriptions/CustomDependenciesTests.cs
index 2d4b0edea..33b36317b 100644
--- a/src/KurrentDB/test/Eventuous.Tests.KurrentDB/Subscriptions/CustomDependenciesTests.cs
+++ b/src/KurrentDB/test/Eventuous.Tests.KurrentDB/Subscriptions/CustomDependenciesTests.cs
@@ -106,7 +106,7 @@ public ValueTask StoreCheckpoint(Checkpoint checkpoint, bool force,
class TestSerializer : IEventSerializer {
public DeserializationResult DeserializeEvent(ReadOnlySpan data, string eventType, string contentType) {
- var result = DefaultEventSerializer.Instance.DeserializeEvent(data, eventType, contentType);
+ var result = EventSerializer.Default.DeserializeEvent(data, eventType, contentType);
if (result is not DeserializationResult.SuccessfullyDeserialized { Payload: var evt }) {
return result;
diff --git a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Eventuous.Tests.Projections.MongoDB.csproj b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Eventuous.Tests.Projections.MongoDB.csproj
index ea0cab941..5aa7fd95a 100644
--- a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Eventuous.Tests.Projections.MongoDB.csproj
+++ b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Eventuous.Tests.Projections.MongoDB.csproj
@@ -11,6 +11,7 @@
+
diff --git a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/IntegrationFixture.cs b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/IntegrationFixture.cs
index fa4c755a3..0c8f0e550 100644
--- a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/IntegrationFixture.cs
+++ b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/IntegrationFixture.cs
@@ -26,7 +26,7 @@ public Task AppendEvent(StreamName streamName, object evt, E
);
static IntegrationFixture() {
- DefaultEventSerializer.SetDefaultSerializer(Serializer);
+ EventSerializer.SetDefault(Serializer);
NodaTimeSerializers.Register();
}
diff --git a/src/RabbitMq/src/Eventuous.RabbitMq/Constants.cs b/src/RabbitMq/src/Eventuous.RabbitMq/Constants.cs
deleted file mode 100644
index 477d5cbd2..000000000
--- a/src/RabbitMq/src/Eventuous.RabbitMq/Constants.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright (C) Eventuous HQ OÜ. All rights reserved
-// Licensed under the Apache License, Version 2.0.
-
-namespace Eventuous.RabbitMq;
-
-internal static class AttrConstants {
- internal const string DynamicSerializationMessage = "Only works with AOT when using DefaultStaticEventSerializer";
-}
diff --git a/src/RabbitMq/src/Eventuous.RabbitMq/Producers/RabbitMqProducer.cs b/src/RabbitMq/src/Eventuous.RabbitMq/Producers/RabbitMqProducer.cs
index 4f9bcd880..275d62840 100644
--- a/src/RabbitMq/src/Eventuous.RabbitMq/Producers/RabbitMqProducer.cs
+++ b/src/RabbitMq/src/Eventuous.RabbitMq/Producers/RabbitMqProducer.cs
@@ -40,7 +40,7 @@ public RabbitMqProducer(
: base(TracingOptions) {
_log = log;
_options = options;
- _serializer = serializer ?? DefaultEventSerializer.Instance;
+ _serializer = serializer ?? EventSerializer.Default;
_connectionFactory = Ensure.NotNull(connectionFactory);
_exchangeCache = new(_log);
}
@@ -60,8 +60,6 @@ public Task StartAsync(CancellationToken cancellationToken = default) {
ProduceOperation = "publish"
};
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
protected override async Task ProduceMessages(
StreamName stream,
IEnumerable messages,
@@ -96,8 +94,6 @@ await failed
.NoContext();
}
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
void Publish(string stream, ProducedMessage message, RabbitMqProduceOptions? options) {
if (_channel == null) throw new InvalidOperationException("Producer hasn't been initialized, call Initialize");
diff --git a/src/RabbitMq/src/Eventuous.RabbitMq/Subscriptions/RabbitMqSubscription.cs b/src/RabbitMq/src/Eventuous.RabbitMq/Subscriptions/RabbitMqSubscription.cs
index df39635c7..1b2bd7379 100644
--- a/src/RabbitMq/src/Eventuous.RabbitMq/Subscriptions/RabbitMqSubscription.cs
+++ b/src/RabbitMq/src/Eventuous.RabbitMq/Subscriptions/RabbitMqSubscription.cs
@@ -93,8 +93,6 @@ public RabbitMqSubscription(
eventSerializer
) { }
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
protected override ValueTask Subscribe(CancellationToken cancellationToken) {
var exchange = Ensure.NotEmptyString(Options.Exchange);
@@ -142,8 +140,6 @@ protected override ValueTask Subscribe(CancellationToken cancellationToken) {
const string ReceivedMessageKey = "receivedMessage";
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
async Task HandleReceived(object sender, BasicDeliverEventArgs received) {
Logger.Current = Log;
@@ -172,8 +168,6 @@ ValueTask Nack(IMessageConsumeContext ctx, Exception exception) {
return default;
}
- [RequiresUnreferencedCode(AttrConstants.DynamicSerializationMessage)]
- [RequiresDynamicCode(AttrConstants.DynamicSerializationMessage)]
MessageConsumeContext CreateContext(object sender, BasicDeliverEventArgs received) {
var evt = DeserializeData(received.BasicProperties.ContentType, received.BasicProperties.Type, received.Body, received.Exchange);
diff --git a/src/Redis/src/Eventuous.Redis/RedisStore.cs b/src/Redis/src/Eventuous.Redis/RedisStore.cs
index 7a9cd2f23..a4a733693 100644
--- a/src/Redis/src/Eventuous.Redis/RedisStore.cs
+++ b/src/Redis/src/Eventuous.Redis/RedisStore.cs
@@ -29,7 +29,7 @@ public RedisStore(
IEventSerializer? serializer = null,
IMetadataSerializer? metaSerializer = null
) {
- _serializer = serializer ?? DefaultEventSerializer.Instance;
+ _serializer = serializer ?? EventSerializer.Default;
_metaSerializer = metaSerializer ?? DefaultMetadataSerializer.Instance;
_getDatabase = Ensure.NotNull(getDatabase, "Connection factory");
}
diff --git a/src/Redis/test/Eventuous.Tests.Redis/Eventuous.Tests.Redis.csproj b/src/Redis/test/Eventuous.Tests.Redis/Eventuous.Tests.Redis.csproj
index 78daa2ab3..afd7d48da 100644
--- a/src/Redis/test/Eventuous.Tests.Redis/Eventuous.Tests.Redis.csproj
+++ b/src/Redis/test/Eventuous.Tests.Redis/Eventuous.Tests.Redis.csproj
@@ -16,5 +16,6 @@
+
diff --git a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/IntegrationFixture.cs b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/IntegrationFixture.cs
index a4600945d..4e0ec7ea5 100644
--- a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/IntegrationFixture.cs
+++ b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/IntegrationFixture.cs
@@ -18,7 +18,7 @@ public sealed class IntegrationFixture : IAsyncInitializer, IAsyncDisposable {
IEventSerializer Serializer { get; } = new DefaultEventSerializer(TestPrimitives.DefaultOptions);
- public IntegrationFixture() => DefaultEventSerializer.SetDefaultSerializer(Serializer);
+ public IntegrationFixture() => EventSerializer.SetDefault(Serializer);
public async Task InitializeAsync() {
_redisContainer = new RedisBuilder().WithImage("redis:7.0.12-alpine").Build();
diff --git a/src/Relational/src/Eventuous.Sql.Base/Constants.cs b/src/Relational/src/Eventuous.Sql.Base/Constants.cs
deleted file mode 100644
index 932f86c6f..000000000
--- a/src/Relational/src/Eventuous.Sql.Base/Constants.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright (C) Eventuous HQ OÜ. All rights reserved
-// Licensed under the Apache License, Version 2.0.
-
-namespace Eventuous.Sql.Base;
-
-internal static class Constants {
- internal const string DynamicSerializationMessage = "Only works with AOT when using DefaultStaticEventSerializer";
-}
diff --git a/src/Relational/src/Eventuous.Sql.Base/Producers/UniversalProducer.cs b/src/Relational/src/Eventuous.Sql.Base/Producers/UniversalProducer.cs
index 66946706e..efe2877e8 100644
--- a/src/Relational/src/Eventuous.Sql.Base/Producers/UniversalProducer.cs
+++ b/src/Relational/src/Eventuous.Sql.Base/Producers/UniversalProducer.cs
@@ -11,8 +11,6 @@ namespace Eventuous.Sql.Base.Producers;
///
public class UniversalProducer(IEventStore store) : IProducer {
///
- [RequiresDynamicCode(Constants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(Constants.DynamicSerializationMessage)]
public async Task Produce(StreamName stream, IEnumerable messages, CancellationToken cancellationToken = default) {
var events = messages.Select(ToStreamEvent).ToList();
await store.AppendEvents(stream, ExpectedStreamVersion.Any, events, cancellationToken);
diff --git a/src/Relational/src/Eventuous.Sql.Base/SqlEventStoreBase.cs b/src/Relational/src/Eventuous.Sql.Base/SqlEventStoreBase.cs
index 1c9870e3d..e093be1a0 100644
--- a/src/Relational/src/Eventuous.Sql.Base/SqlEventStoreBase.cs
+++ b/src/Relational/src/Eventuous.Sql.Base/SqlEventStoreBase.cs
@@ -19,7 +19,7 @@ namespace Eventuous.Sql.Base;
/// Database transaction type
public abstract class SqlEventStoreBase(IEventSerializer? serializer, IMetadataSerializer? metaSerializer) : IEventStore
where TConnection : DbConnection where TTransaction : DbTransaction {
- protected IEventSerializer Serializer { get; } = serializer ?? DefaultEventSerializer.Instance;
+ protected IEventSerializer Serializer { get; } = serializer ?? EventSerializer.Default;
protected IMetadataSerializer MetaSerializer { get; } = metaSerializer ?? DefaultMetadataSerializer.Instance;
const string ContentType = "application/json";
@@ -91,8 +91,6 @@ StreamTruncatePosition position
);
///
- [RequiresDynamicCode(Constants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(Constants.DynamicSerializationMessage)]
public async IAsyncEnumerable ReadEvents(StreamName stream, StreamReadPosition start, int count, [EnumeratorCancellation] CancellationToken cancellationToken) {
if (count <= 0 || start == StreamReadPosition.End) yield break;
@@ -102,8 +100,6 @@ public async IAsyncEnumerable ReadEvents(StreamName stream, StreamR
}
///
- [RequiresDynamicCode(Constants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(Constants.DynamicSerializationMessage)]
public async IAsyncEnumerable ReadEventsBackwards(StreamName stream, StreamReadPosition start, int count, [EnumeratorCancellation] CancellationToken cancellationToken) {
if (count <= 0) yield break;
@@ -112,8 +108,6 @@ public async IAsyncEnumerable ReadEventsBackwards(StreamName stream
foreach (var evt in events) yield return evt;
}
- [RequiresDynamicCode("Calls Eventuous.Sql.Base.SqlEventStoreBase.ToStreamEvent(PersistedEvent)")]
- [RequiresUnreferencedCode("Calls Eventuous.Sql.Base.SqlEventStoreBase.ToStreamEvent(PersistedEvent)")]
async Task ReadInternal(StreamName stream, StreamReadPosition start, int count, CancellationToken cancellationToken) {
await using var connection = await OpenConnection(cancellationToken).NoContext();
await using var cmd = GetReadCommand(connection, stream, start, count);
@@ -121,8 +115,6 @@ async Task ReadInternal(StreamName stream, StreamReadPosition sta
return await ReadFromCommand(cmd, stream, cancellationToken).NoContext();
}
- [RequiresDynamicCode("Calls Eventuous.Sql.Base.SqlEventStoreBase.ToStreamEvent(PersistedEvent)")]
- [RequiresUnreferencedCode("Calls Eventuous.Sql.Base.SqlEventStoreBase.ToStreamEvent(PersistedEvent)")]
async Task ReadInternalBackwards(StreamName stream, StreamReadPosition start, int count, CancellationToken cancellationToken) {
await using var connection = await OpenConnection(cancellationToken).NoContext();
await using var cmd = GetReadBackwardsCommand(connection, stream, start, count);
@@ -130,8 +122,6 @@ async Task ReadInternalBackwards(StreamName stream, StreamReadPos
return await ReadFromCommand(cmd, stream, cancellationToken).NoContext();
}
- [RequiresDynamicCode("Calls Eventuous.Sql.Base.SqlEventStoreBase.ToStreamEvent(PersistedEvent)")]
- [RequiresUnreferencedCode("Calls Eventuous.Sql.Base.SqlEventStoreBase.ToStreamEvent(PersistedEvent)")]
async Task ReadFromCommand(DbCommand cmd, StreamName stream, CancellationToken cancellationToken) {
try {
await using var reader = await cmd.ExecuteReaderAsync(cancellationToken).NoContext();
@@ -146,8 +136,6 @@ async Task ReadFromCommand(DbCommand cmd, StreamName stream, Canc
}
}
- [RequiresDynamicCode("Calls Eventuous.IEventSerializer.DeserializeEvent(ReadOnlySpan, String, String)")]
- [RequiresUnreferencedCode("Calls Eventuous.IEventSerializer.DeserializeEvent(ReadOnlySpan, String, String)")]
StreamEvent ToStreamEvent(PersistedEvent evt) {
var deserialized = Serializer.DeserializeEvent(Encoding.UTF8.GetBytes(evt.JsonData), evt.MessageType, ContentType);
@@ -163,8 +151,6 @@ StreamEvent ToStreamEvent(PersistedEvent evt) {
}
///
- [RequiresDynamicCode(Constants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(Constants.DynamicSerializationMessage)]
public virtual async Task AppendEvents(
StreamName stream,
ExpectedStreamVersion expectedVersion,
@@ -195,8 +181,6 @@ CancellationToken cancellationToken
throw IsConflict(e) ? new AppendToStreamException(stream, e) : e;
}
- [RequiresUnreferencedCode("Calls Eventuous.IEventSerializer.SerializeEvent(Object)")]
- [RequiresDynamicCode("Calls Eventuous.IEventSerializer.SerializeEvent(Object)")]
NewPersistedEvent Convert(NewStreamEvent evt) {
var data = Serializer.SerializeEvent(evt.Payload!);
var meta = MetaSerializer.Serialize(evt.Metadata);
@@ -208,8 +192,6 @@ NewPersistedEvent Convert(NewStreamEvent evt) {
}
///
- [RequiresDynamicCode(Constants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(Constants.DynamicSerializationMessage)]
public virtual async Task AppendEvents(IReadOnlyCollection appends, CancellationToken cancellationToken) {
if (appends.Count == 0) return [];
@@ -242,8 +224,6 @@ public virtual async Task AppendEvents(IReadOnlyCollection
throw IsConflict(e) ? new AppendToStreamException(streamNames, e) : e;
}
- [RequiresUnreferencedCode("Calls Eventuous.IEventSerializer.SerializeEvent(Object)")]
- [RequiresDynamicCode("Calls Eventuous.IEventSerializer.SerializeEvent(Object)")]
NewPersistedEvent Convert(NewStreamEvent evt) {
var data = Serializer.SerializeEvent(evt.Payload!);
var meta = MetaSerializer.Serialize(evt.Metadata);
diff --git a/src/Relational/src/Eventuous.Sql.Base/Subscriptions/SqlSubscriptionBase.cs b/src/Relational/src/Eventuous.Sql.Base/Subscriptions/SqlSubscriptionBase.cs
index f63bc6830..6659b4086 100644
--- a/src/Relational/src/Eventuous.Sql.Base/Subscriptions/SqlSubscriptionBase.cs
+++ b/src/Relational/src/Eventuous.Sql.Base/Subscriptions/SqlSubscriptionBase.cs
@@ -76,8 +76,6 @@ public abstract class SqlSubscriptionBase(
private record DetectedGap(long Position, DateTime FirstSeen);
- [RequiresUnreferencedCode("Calls ExecutePollCycle()")]
- [RequiresDynamicCode("Calls ExecutePollCycle()")]
async Task PollingQuery(ulong? position, CancellationToken cancellationToken) {
var start = position.HasValue ? (long)position : -1;
@@ -94,8 +92,6 @@ async Task PollingQuery(ulong? position, CancellationToken cancellationToken) {
return;
- [RequiresUnreferencedCode("Calls Eventuous.Sql.Base.Subscriptions.SqlSubscriptionBase.ToConsumeContext(PersistedEvent, CancellationToken)")]
- [RequiresDynamicCode("Calls Eventuous.Sql.Base.Subscriptions.SqlSubscriptionBase.ToConsumeContext(PersistedEvent, CancellationToken)")]
async Task Poll() {
try {
await using var connection = await OpenConnection(cancellationToken).NoContext();
@@ -153,8 +149,6 @@ async Task Poll() {
}
}
- [RequiresDynamicCode("Calls Poll()")]
- [RequiresUnreferencedCode("Calls Poll()")]
async Task ExecutePollCycle() {
while (!cancellationToken.IsCancellationRequested) {
var result = await Poll().NoContext();
@@ -208,8 +202,6 @@ async Task ExecutePollCycle() {
/// Starts the subscription
///
///
- [RequiresDynamicCode(Constants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(Constants.DynamicSerializationMessage)]
protected override async ValueTask Subscribe(CancellationToken cancellationToken) {
await BeforeSubscribe(cancellationToken).NoContext();
var (_, position) = await GetCheckpoint(cancellationToken).NoContext();
@@ -250,8 +242,6 @@ protected override async ValueTask Unsubscribe(CancellationToken cancellationTok
SubscriptionKind.Stream => evt.StreamPosition
};
- [RequiresDynamicCode(Constants.DynamicSerializationMessage)]
- [RequiresUnreferencedCode(Constants.DynamicSerializationMessage)]
MessageConsumeContext ToConsumeContext(PersistedEvent evt, CancellationToken cancellationToken) {
Logger.Current = Log;
diff --git a/src/Sqlite/src/Eventuous.Sqlite/SqliteStore.cs b/src/Sqlite/src/Eventuous.Sqlite/SqliteStore.cs
index c93565ea0..010fe1da0 100644
--- a/src/Sqlite/src/Eventuous.Sqlite/SqliteStore.cs
+++ b/src/Sqlite/src/Eventuous.Sqlite/SqliteStore.cs
@@ -74,8 +74,6 @@ NewPersistedEvent[] events
)
=> throw new NotSupportedException("SQLite does not use GetAppendCommand. AppendEvents is overridden directly.");
- [RequiresDynamicCode("Only works with AOT when using DefaultStaticEventSerializer")]
- [RequiresUnreferencedCode("Only works with AOT when using DefaultStaticEventSerializer")]
public override async Task AppendEvents(
StreamName stream,
ExpectedStreamVersion expectedVersion,
@@ -107,8 +105,6 @@ CancellationToken cancellationToken
}
///
- [RequiresDynamicCode("Only works with AOT when using DefaultStaticEventSerializer")]
- [RequiresUnreferencedCode("Only works with AOT when using DefaultStaticEventSerializer")]
public override async Task AppendEvents(IReadOnlyCollection appends, CancellationToken cancellationToken) {
if (appends.Count == 0) return [];
@@ -230,8 +226,6 @@ RETURNING global_position
return new((ulong)lastGlobalPosition, newVersion);
}
- [RequiresUnreferencedCode("Calls Eventuous.IEventSerializer.SerializeEvent(Object)")]
- [RequiresDynamicCode("Calls Eventuous.IEventSerializer.SerializeEvent(Object)")]
NewPersistedEvent Convert(NewStreamEvent evt) {
var data = Serializer.SerializeEvent(evt.Payload!);
var meta = MetaSerializer.Serialize(evt.Metadata);
diff --git a/src/Sqlite/test/Eventuous.Tests.Sqlite/Eventuous.Tests.Sqlite.csproj b/src/Sqlite/test/Eventuous.Tests.Sqlite/Eventuous.Tests.Sqlite.csproj
index 7b1670dd0..b8ca40d56 100644
--- a/src/Sqlite/test/Eventuous.Tests.Sqlite/Eventuous.Tests.Sqlite.csproj
+++ b/src/Sqlite/test/Eventuous.Tests.Sqlite/Eventuous.Tests.Sqlite.csproj
@@ -20,5 +20,6 @@
+