Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serializer settings to be configured #19

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

benfoster
Copy link
Owner

There are two factors that influence the way in which events are serialized to CosmosDB.

  1. The settings provided when intializing the Cosmos client, for example:
static CosmosClient CreateCosmosClient(string accountEndpoint)
    => new(
        accountEndpoint: accountEndpoint,
        tokenCredential: new DefaultAzureCredential(),
        new CosmosClientOptions
        {
            ApplicationName = "psp-payment-processor",
            Serializer = new CosmosJsonSerializer(SerializerSettings.Default)
        }
    );
  1. The settings used when serializing the event payload (from CosmosEvent.cs):
    public static CosmosEvent FromEventData(string streamId, long eventNumber, EventData @event, JsonSerializer serializer)
        => new()
        {
            Id = GenerateId(eventNumber, streamId),
            EventId = @event.Id,
            StreamId = streamId,
            EventType = @event.EventType,
            Data = JObject.FromObject(@event.Data, serializer),
            EventNumber = eventNumber,
            Metadata = @event.Metadata
        };

The latter was hardcoded to SerializerSettings.Default so regardless of the settings configured on the Cosmos client, they wouldn't have any impact on the serialization of the actual event payload.

This PR makes it configurable.

@benfoster benfoster merged commit 9f4cd43 into main Nov 23, 2023
1 check passed
@benfoster benfoster deleted the task/make-serializer-settings-configurable branch November 23, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant