Skip to content

Commit f8d418e

Browse files
committed
Abstract JSON serialization behind installable serializer packages
Core EventFlow no longer depends on Newtonsoft.Json. JSON serialization is now provided by separate, client-selectable packages: - EventFlow.Serialization.NewtonsoftJson (AddNewtonsoftJson) - EventFlow.Serialization.SystemTextJson (AddSystemTextJson) Core changes (breaking): - Removed JsonSerializer, SingleValueObjectConverter, IJsonOptions/JsonOptions/ ChainedJsonOptions, JsonOptionsExtensions and ConfigureJson from core. - Dropped the Newtonsoft.Json package reference. - Added ThrowingJsonSerializer as the default IJsonSerializer so a missing serializer registration fails fast with an actionable message. - Removed Newtonsoft serialization attributes from core/sub-package types ([JsonIgnore] on Metadata/SnapshotMetadata, [JsonConverter] on CacheKey, [JsonProperty] on MongoDB data models, [JsonConverter] on example ids). These were inert under the dictionary/BSON contracts. - InMemoryEventPersistence now uses the injected IJsonSerializer. Behavior preserved: SingleValueObjects keep serializing as objects by default (the bare-value SingleValueObjectConverter remains an opt-in), so existing event/snapshot stores remain readable. Added a provider-agnostic TestSuiteForJsonSerializer conformance suite; both serializer packages pass it. Test bootstrapping and EventFlow.Tests updated to register Newtonsoft explicitly. Note: EventFlow.AspNetCore is not part of the solution and is left untouched.
1 parent 4c070a0 commit f8d418e

56 files changed

Lines changed: 1014 additions & 647 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

EventFlow.sln

Lines changed: 466 additions & 215 deletions
Large diffs are not rendered by default.

Source/EventFlow.EntityFramework.Tests/EntityFrameworkTestExtensions.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ public static class EntityFrameworkTestExtensions
3535
public static IEventFlowOptions ConfigureForEventStoreTest(this IEventFlowOptions options)
3636
{
3737
return options
38-
.UseEntityFrameworkEventStore<TestDbContext>();
38+
.UseEntityFrameworkEventStore<TestDbContext>()
39+
.AddNewtonsoftJson();
3940
}
4041

4142
public static IEventFlowOptions ConfigureForSnapshotStoreTest(this IEventFlowOptions options)
4243
{
4344
return options
44-
.UseEntityFrameworkSnapshotStore<TestDbContext>();
45+
.UseEntityFrameworkSnapshotStore<TestDbContext>()
46+
.AddNewtonsoftJson();
4547
}
4648

4749
public static IEventFlowOptions ConfigureForReadStoreTest(this IEventFlowOptions options)
@@ -53,14 +55,16 @@ public static IEventFlowOptions ConfigureForReadStoreTest(this IEventFlowOptions
5355
.AddQueryHandlers(
5456
typeof(EfThingyGetQueryHandler),
5557
typeof(EfThingyGetVersionQueryHandler),
56-
typeof(EfThingyGetMessagesQueryHandler));
58+
typeof(EfThingyGetMessagesQueryHandler))
59+
.AddNewtonsoftJson();
5760
}
5861

5962
public static IEventFlowOptions ConfigureForReadStoreIncludeTest(this IEventFlowOptions options)
6063
{
6164
return options
6265
.UseEntityFrameworkReadModel<PersonReadModelEntity, TestDbContext>(cfg => cfg.Include(x => x.Addresses))
63-
.AddQueryHandlers(typeof(PersonGetQueryHandler));
66+
.AddQueryHandlers(typeof(PersonGetQueryHandler))
67+
.AddNewtonsoftJson();
6468
}
6569
}
6670
}

Source/EventFlow.Examples.Shipping.Queries.InMemory/EventFlow.Examples.Shipping.Queries.InMemory.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<ProjectReference Include="..\EventFlow.Examples.Shipping\EventFlow.Examples.Shipping.csproj" />
8+
<ProjectReference Include="..\EventFlow.Serialization.NewtonsoftJson\EventFlow.Serialization.NewtonsoftJson.csproj" />
89
</ItemGroup>
910
</Project>

Source/EventFlow.Examples.Shipping.Queries.InMemory/EventFlowExamplesShippingQueriesInMemory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public static IEventFlowOptions ConfigureShippingQueriesInMemory(
3737
return eventFlowOptions
3838
.AddQueryHandlers(Assembly)
3939
.UseInMemoryReadStoreFor<VoyageReadModel>()
40-
.UseInMemoryReadStoreFor<CargoReadModel>();
40+
.UseInMemoryReadStoreFor<CargoReadModel>()
41+
.AddNewtonsoftJson();
4142
}
4243
}
4344
}

Source/EventFlow.Examples.Shipping/Domain/Model/CargoModel/CargoId.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222

2323
using EventFlow.Core;
2424
using EventFlow.ValueObjects;
25-
using Newtonsoft.Json;
2625

2726
namespace EventFlow.Examples.Shipping.Domain.Model.CargoModel
2827
{
29-
[JsonConverter(typeof(SingleValueObjectConverter))]
3028
public class CargoId : Identity<CargoId>
3129
{
3230
public CargoId(string value) : base(value)

Source/EventFlow.Examples.Shipping/Domain/Model/CargoModel/Entities/TransportLegId.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222

2323
using EventFlow.Core;
2424
using EventFlow.ValueObjects;
25-
using Newtonsoft.Json;
2625

2726
namespace EventFlow.Examples.Shipping.Domain.Model.CargoModel.Entities
2827
{
29-
[JsonConverter(typeof(SingleValueObjectConverter))]
3028
public class TransportLegId : Identity<TransportLegId>
3129
{
3230
public TransportLegId(string value) : base(value)

Source/EventFlow.Examples.Shipping/Domain/Model/LocationModel/LocationId.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
using System.Text.RegularExpressions;
2525
using EventFlow.Core;
2626
using EventFlow.ValueObjects;
27-
using Newtonsoft.Json;
2827

2928
namespace EventFlow.Examples.Shipping.Domain.Model.LocationModel
3029
{
31-
[JsonConverter(typeof(SingleValueObjectConverter))]
3230
public class LocationId : SingleValueObject<string>, IIdentity
3331
{
3432
private static readonly Regex ValidValues = new Regex("[a-zA-Z]{2}[a-zA-Z2-9]{3}", RegexOptions.Compiled);

Source/EventFlow.Examples.Shipping/Domain/Model/VoyageModel/VoyageId.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222

2323
using EventFlow.Core;
2424
using EventFlow.ValueObjects;
25-
using Newtonsoft.Json;
2625

2726
namespace EventFlow.Examples.Shipping.Domain.Model.VoyageModel
2827
{
29-
[JsonConverter(typeof(SingleValueObjectConverter))]
3028
public class VoyageId : SingleValueObject<string>, IIdentity
3129
{
3230
public VoyageId(string value) : base(value)

Source/EventFlow.MongoDB/ValueObjects/MongoDbEventDataModel.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
using EventFlow.ValueObjects;
2626
using MongoDB.Bson;
2727
using MongoDB.Bson.Serialization.Attributes;
28-
using Newtonsoft.Json;
2928

3029
namespace EventFlow.MongoDB.ValueObjects
3130
{
@@ -34,25 +33,19 @@ public class MongoDbEventDataModel : ValueObject, ICommittedDomainEvent
3433
[BsonElement("_id")]
3534
public long _id { get; set; }
3635

37-
[JsonProperty("batchId")]
3836
[BsonGuidRepresentation(GuidRepresentation.Standard)]
3937
public Guid BatchId { get; set; }
4038

4139
long? _version { get; set; }
4240

43-
[JsonProperty("aggregateId")]
4441
public string AggregateId { get; set; }
4542

46-
[JsonProperty("aggregateName")]
4743
public string AggregateName { get; set; }
4844

49-
[JsonProperty("aggregateSequenceNumber")]
5045
public int AggregateSequenceNumber { get; set; }
5146

52-
[JsonProperty("data")]
5347
public string Data { get; set; }
5448

55-
[JsonProperty("metaData")]
5649
public string Metadata { get; set; }
5750
}
5851
}

Source/EventFlow.MongoDB/ValueObjects/MongoDbSnapshotDataModel.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using EventFlow.ValueObjects;
2424
using MongoDB.Bson;
2525
using MongoDB.Bson.Serialization.Attributes;
26-
using Newtonsoft.Json;
2726

2827
namespace EventFlow.MongoDB.ValueObjects
2928
{
@@ -32,15 +31,10 @@ public class MongoDbSnapshotDataModel : ValueObject
3231
[BsonElement("_id")]
3332
public ObjectId _id { get; set; }
3433
long? _version { get; set; }
35-
[JsonProperty("aggregateId")]
3634
public string AggregateId { get; set; }
37-
[JsonProperty("aggregateName")]
3835
public string AggregateName { get; set; }
39-
[JsonProperty("aggregateSequenceNumber")]
4036
public int AggregateSequenceNumber { get; set; }
41-
[JsonProperty("data")]
4237
public string Data { get; set; }
43-
[JsonProperty("metaData")]
4438
public string Metadata { get; set; }
4539
}
4640
}

0 commit comments

Comments
 (0)