ASOS / SimpleEventStore

SimpleEventStore
MIT License
81 stars 24 forks source link

Added JsonSerializerSettings / JsonSerializer support #28

Closed stevewgh closed 5 years ago

stevewgh commented 6 years ago

Any methods that use JObject.FromObject or JObject.ToObject can now use a JsonSerializer which is constructed from a JsonSerializationSettings instance, allowing custom serialization rules to be applied transparently without the event store being aware.

The JsonSerializationSettings instance is injected from the AzureDocumentDbStorageEngineBuilder. This allows custom serialization converters (and other Json.Net extensions) to be provided to the AzureDocumentDbStorageEngine and allows control over how the events are serialized.

I tried to avoid this change by providing the JsonSerializationSettings instance to the DocumentClient, but the use of JObject.FromObject and JObject.ToObject used their own JsonSerializationSettings which ignored the converters.

An alternative to this PR is to change the type of the DocumentDbStorageEvent.Body property to object instead of JObject which would force the DocumentClient to perform the body serialization, however, this may break existing stores due to the contract change.

Some use cases for this level of event serialization

asosMikeGore commented 5 years ago

Hi Steve,

Thanks for this, the PR looks good! I've appended some changes to your PR to update the docs, and also change the existing when_initializing_all_expected_resources_are_created test. It looks like Cosmos is now adding additional exclude paths when creating collections to ignore the etag field, which then breaks the count assertions. Therefore, I've just tweaked the assertion to take this into account.