DotNet4Neo4j / Neo4jClient

.NET client binding for Neo4j
https://www.nuget.org/packages/Neo4jClient
Microsoft Public License
431 stars 146 forks source link

Docs diff between BoltGraphClient and GraphClient and lifetime management #453

Closed agecas closed 1 year ago

agecas commented 1 year ago

I have a few questions around how to choose between GraphClient and BoltGraphClient?

What are the criteria for each and API differences?

I noticed that GraphClient (HTTP) has a factory with a fairly good example in the docs, but BoltGraphClient doesn't have it. As far as I understand BoltGraphClient should be long lived with an active connection.

Having said that if BoltGraphClient is used, following questions arise:

I appreciate this is not a bug, but perhaps an improvement and I couldn't find much help online.

Questions written with latest Neo4jClient (v5.x.x) in mind.

cskardon commented 1 year ago

The decision between the two is largely down to which protocol you want to use. You might be forced into using one over the other, for example - Aura will require Bolt, but if it's on prem - either/or - and you can swap out the client as long as you're using IGraphClient throughout your code base.

There is no factory for the BoltGraphClient, I'm not likely to write it, I use DI (similar to Autofact as shown on the wiki - which I've updated).

The thing you need to bear in mind is cost - you can instantiate a new instance for every call - that will be costly and slow - as you have to connect and create the underlying driver instances (for the BoltGraphClient) - or you can run it as a Singleton - API/WorkerService - same deal - ideally treat the Client as a Singleton. In something like a website - maybe that's on a per user session basis - on something like an Azure Function you can use DI as well (Blog post here - though this may be out of date now).

I've also updated the Transaction docs