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

Working with Aura DB #445

Open
mcalvin-kinectify opened this issue Jun 1, 2022 · 3 comments
Open

Working with Aura DB #445

mcalvin-kinectify opened this issue Jun 1, 2022 · 3 comments

Comments

@mcalvin-kinectify
Copy link

Hello,
We have been using this client on a local neo4j instance and have upgraded to Neo4j's hosted Aura database instead. Aura appears to only support the neo4j+s bolt protocol, and I am getting a messages that the protocol is not supported by Neo4jClient. Is that correct and the client won't work with Aura or am I doing something wrong? Here is how I am injecting the client into the dependency injection container:

 services.AddSingleton(context =>
  {
      var path = config.GetValue<string>("Neo4j:Path");
      if (!path.StartsWith("http") && !path.StartsWith("neo4j")) // note with aura db this condition would not be met (starts with neo4j+s)
      {
          path = $"http://{path}:7474"; // add the neo4j protocol and port if it isn't provided
      }

      return NeoServerConfiguration.GetConfigurationAsync(
          new Uri(path),
          config.GetValue<string>("Neo4j:User"),
          config.GetValue<string>("Neo4j:Password")
      ).GetAwaiter().GetResult();
  });

  services.AddSingleton<IGraphClientFactory, GraphClientFactory>();
@mcalvin-kinectify
Copy link
Author

Here is the exception I am receiving:
image

@mcalvin-kinectify
Copy link
Author

I was able to get a successful connection by doing this:

services.AddScoped(context =>
{
    var path = config.GetValue<string>("Neo4j:Path");

    return GraphDatabase.Driver(path, AuthTokens.Basic(config.GetValue<string>("Neo4j:User"),
        config.GetValue<string>("Neo4j:Password")));
});

services.AddScoped<IBoltGraphClient>(x =>
{
    var driver = x.GetService<IDriver>();
    return new BoltGraphClient(driver);
});

and then injecting IBoltGraphClient instead of IGraphClientFactory. Unfortunately, if the BoltGraphClient gets disposed, the underlying driver is disposed also. So it doesn't look like I can reuse the GraphDatabase.Driver and have to register it as Scoped instead of a Singleton.

@cjpomer
Copy link

cjpomer commented Mar 19, 2023

I have run into the same issue working with Aura DB.

@mcalvin-kinectify for my understanding/curiosity, the issue with a Scoped lifetime is that you have to call BoltGraphClient.ConnectAsync with each connection, right?

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

No branches or pull requests

2 participants