Database Reference
In-Depth Information
Neo4jModule and Ninject
To avoid repeating the connection information through out the application, the application makes use of the open
source dependency injector, Ninject.
Ninject is included as part of the application configuration, so you shouldn't need to do anything to make it
work during the review of the application.
Note
Ninject works by binding the Neo4jClient to the application using the Neo4jModule located in the App_Start/
Modules folder, a snippet of which is shown in Listing 7-12.
Listing 7-12. Neo4jModule.cs
public class Neo4jModule : NinjectModule
{
/// <summary>Loads the module into the kernel.</summary>
public override void Load()
{
Bind<IGraphClient>().ToMethod(InitNeo4JClient).InSingletonScope();
}
private static IGraphClient InitNeo4JClient(IContext context)
{
var neo4JUri = new Uri(ConfigurationManager.ConnectionStrings["graphStory"].
ConnectionString);
var graphClient = new GraphClient(neo4JUri);
graphClient.Connect();
return graphClient;
}
}
Once the Neo4jModule is added, it can be registered with the application in the NinjectWebCommon file, which
is located in the App_Start folder. The module is registered in the RegisterServices method as shown in Listing 7-13.
Once the Module is registered, an IGraphClient instance can be called within the application, such as within the
service layer, to perform operations on your database.
 
 
Search WWH ::




Custom Search