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

More serialization configuration #41

Merged
merged 1 commit into from
Apr 14, 2021

Conversation

carl-berg
Copy link
Member

@carl-berg carl-berg commented Apr 13, 2021

Enables configuration of CosmosClient in order to fully configure serialization (until #40 is solved).
This PR enables a user to configure the same serialization for both DocumentClient and CosmosClient which is a bit cumbersome, but at least possible. Example:

public static DatabaseOptions<MyDatbase> BuildDatabaseOptions(string connectionString)
{
    var builder = new DatabaseOptionsBuilder<MyDatbase>().UseConnectionString(connectionString);
    builder.Options.DatabaseId = "MyDb";
    builder.Options.ConfigureJsonSerializerSettings = settings =>
    {
        settings.Converters.Add(new CosmosDbJsonSerialization.CustomJsonConverter());
        builder.Options.ConfigureCosmosClientOptions = options =>
        {
            options.Serializer = new CosmosDbJsonSerialization.CosmosJsonNetSerializer(settings);
        };
    };

    return builder.Options;
}

An example of a CosmosJsonNetSerializer can be found here: https://gist.github.com/richstokoe/c82fc831c6b4020926f5b5f772f7cd70

@carl-berg carl-berg merged commit 5ae8464 into master Apr 14, 2021
@carl-berg carl-berg deleted the configurable-json-serializer-settings branch April 14, 2021 06:53
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.

2 participants