Closed HMoen closed 5 years ago
You don't have to populate anything. Leaving it null will pass the responsibility to the DocumentClient to initialize it (which was the previous behavior as well). The CosmosStore passes it to the CosmonautClient which passes it to the DocumentClient and visa versa. Leaving it null will let DocumentClient to initialize it which is used in CosmonautClient which is used by the CosmosStore.
If we don't populate it, we'll get a null reference exception upon querying using FindAsync with the following stack trace:
at Cosmonaut.Extensions.DocumentEntityExtensions.GetPartitionKeyDefinitionForEntity(Type type, JsonSerializerSettings serializerSettings)
at Cosmonaut.CosmosStore`1.GetRequestOptions(String id, RequestOptions requestOptions)
at Cosmonaut.CosmosStore`1.FindAsync(String id, RequestOptions requestOptions, CancellationToken cancellationToken)
at Cosmonaut.CosmosStore`1.FindAsync(String id, Object partitionKeyValue, CancellationToken cancellationToken)
When creating the DocumentClient, we initialize it with our custom serializer settings and then use the DC to create the Cosmonaut client.
Ok let me take a closer look at that and get back to you.
Can you provide me with some code to reproduce this since I can't seem to be able to?
Certainly. I’ll try to get it to you tonight.
Ok I got it. It looks like changing serializerSettings.ContractResolver is DefaultContractResolver resolver
to serializerSettings?.ContractResolver is DefaultContractResolver resolver
solves the issue since the code will fall back to the previous behaviour.
Thanks for getting to the bottom of it. We’ll keep the manual add until the next update.
I'll go ahead close since I see https://github.com/Elfocrash/Cosmonaut/commit/7218e528d0b94bdd7067d9d7cfbbdd4a4083bc64
Thanks for the most recent update 2.11.1.
In order to re-use the DocumentClient, the following used to work with 2.10.0:
var client = new CosmonautClient(documentClient);
var store = new CosmosStore<TDocument>(client, "NAME");
Since the most recent update, we have to populate the JsonSerializerSettings property of the cosmos store settings manually with the following since it is null:
store.Settings.JsonSerializerSettings = JsonUtil.SerializerSettingsInternal;
This is not a big deal, but it would be ideal if the new private field _serializerSettings value can be used in the CosmosStore ctor to build Settings.
Thanks in advance.