azure-cosmos-dotnet-repository
azure-cosmos-dotnet-repository copied to clipboard
Add the ability to provide custom ConnectionPolicy
As detailed in the Cosmos documentation, the native client exposes the ability to override the default ConnectionPolicy: https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.documents.client.connectionpolicy?view=azure-dotnet
Many of these settings are quite niche, but there are some standard features (like RequestTimeout and RetryOptions) that it would be useful to be able to override.
For context, my current scenario is a fire-and-forget call to Cosmos (as a non-critical dependency) where I would like to reduce the default request timeout from 10 seconds to 3, but I can also foresee a scenario where we may want to override the rate-limiting retries too.
Hopefully this is enough detail, but let me know if you need more info. Happy to submit a PR for the feature if you agree it's worth adding :)
Hi @AnyaMostowyj - this sounds great!
We currently have the ICosmosClientOptionsProvider
https://github.com/IEvangelist/azure-cosmos-dotnet-repository/blob/2432320ceb0a46227f6f91bed42e54556759bb63/src/Microsoft.Azure.CosmosRepository/Providers/DefaultCosmosClientOptionsProvider.cs#L16
This class provides the options for the CosmosClient
that we create and then cache for the lifetime of the app. We usually specify these properties on the RepositoryOptions
class.
https://github.com/IEvangelist/azure-cosmos-dotnet-repository/blob/2432320ceb0a46227f6f91bed42e54556759bb63/src/Microsoft.Azure.CosmosRepository/Options/RepositoryOptions.cs#L17
We could add the relevant properties for the CosmosClient
on here and then use them in the ICosmosClientOptionsProvider
.
I would be happy to review a PR for this :)
Good stuff, I'll get on the case!
hi @AnyaMostowyj I have just noticed this might already be possible - check this out
https://github.com/IEvangelist/azure-cosmos-dotnet-repository/blob/2432320ceb0a46227f6f91bed42e54556759bb63/src/Microsoft.Azure.CosmosRepository/Extensions/ServiceCollectionExtensions.cs#L42
hi @AnyaMostowyj I have just noticed this might already be possible - check this out
https://github.com/IEvangelist/azure-cosmos-dotnet-repository/blob/2432320ceb0a46227f6f91bed42e54556759bb63/src/Microsoft.Azure.CosmosRepository/Extensions/ServiceCollectionExtensions.cs#L42
Yes, I agree with @mumby0168 - this is possible through that API.
Apologies for the delay, @mumby0168 @IEvangelist , and great spot, this does indeed appear to allow me to pass a custom CosmosClientOptions object. It appears I would need to reference the type directly from the underlying Microsoft.Azure.Cosmos namespace though, instead of being nicely wrapped by a Microsoft.Azure.CosmosRepository type (like RepositoryOptions). Supplying these options also appears to mask the fact that they will override any options supplied using the RepositoryOptions type, or am I misunderstanding the implementation? This may be by design, but I'm not sure it's transparent to the consumer?
Apologies for the delay, @mumby0168 @IEvangelist , and great spot, this does indeed appear to allow me to pass a custom CosmosClientOptions object. It appears I would need to reference the type directly from the underlying Microsoft.Azure.Cosmos namespace though, instead of being nicely wrapped by a Microsoft.Azure.CosmosRepository type (like RepositoryOptions). Supplying these options also appears to mask the fact that they will override any options supplied using the RepositoryOptions type, or am I misunderstanding the implementation? This may be by design, but I'm not sure it's transparent to the consumer?
I think in this case given we aren't trying to hide the library we are wrapping this might be okay as is. What do you think @IEvangelist ?
Can I take it?
I will add properties from ConnectionPolicy
to RepositoryOptions
Apologies for the delay, @mumby0168 @IEvangelist , and great spot, this does indeed appear to allow me to pass a custom CosmosClientOptions object. It appears I would need to reference the type directly from the underlying Microsoft.Azure.Cosmos namespace though, instead of being nicely wrapped by a Microsoft.Azure.CosmosRepository type (like RepositoryOptions). Supplying these options also appears to mask the fact that they will override any options supplied using the RepositoryOptions type, or am I misunderstanding the implementation? This may be by design, but I'm not sure it's transparent to the consumer?
I think in this case given we aren't trying to hide the library we are wrapping this might be okay as is. What do you think @IEvangelist ?
I agree!
Can I take it? I will add properties from
ConnectionPolicy
toRepositoryOptions
I'm ok with that, as long as @AnyaMostowyj and @mumby0168 are?
Closing this one as it is resolved by the user, and the existing API functions.