Azure / azure-kusto-dotnet

Azure Data Explorer (Kusto) SDK for .NET
MIT License
8 stars 5 forks source link

Use ICslQueryProvider in ASP.NET Core #14

Closed fgheysels closed 1 year ago

fgheysels commented 1 year ago

Not a real issue, but I'm looking at some advice. I have an ASP.NET website that needs to query an Adx database. For this, I'm using the Kusto client library (Microsoft.Azure.Kusto.Data).

In the documentation that is available here, I read that it is advised to not create too many instances of the ICslQueryProvider type.

It's strongly recommended that client code does not create "too many" instances of this object. Instead, client code should create an object per connection string and hold on to it for as long as necessary. This allows the client object to efficiently cache resources.

However, does that mean that in a ASP.NET scenario, where you would register this type in the DI container it is advised to register an instance of this type as a Singleton per DB you want to query?

yogilad commented 1 year ago

Kusto Client can be used in parallel in multiple threads, so this sounds like a good approach. Please remember to dispose of the IDataReader response object when done using it, as it holds up resources.

JeroenMBooij commented 1 year ago

@yogilad How do you check if the connection is still open when you want to execute a query on ICslQueryProvider