DEV Community

Cover image for RavenDB embedded with ASP NET Core web API
Ricardo Costa
Ricardo Costa

Posted on • Originally published at blogit.create.pt on

RavenDB embedded with ASP NET Core web API

This post describes how you can set up a simple ASP NET Core web API with Visual Studio 2017 to use an embedded RavenDB. This is a step by step tutorial.

a) You need to create a new ASP.NET Core Web Application with Visual Studio 2017

b) Choose .NET Core; ASP.NET Core 2.1; API

c) Right click the new project -> Manage NuGet packages

d) You have to add a new package source. Settings. New package source.

Name: MyGet

Source: https://www.myget.org/F/ravendb/api/v3/index.json

e) Choose the new source. Add:

RavenDB.Embedded – 4.1.1-nightly-20180904-0430

RavenDB.Client – 4.1.1-nightly-20180904-0430

f) Create a DocumentStoreHolder class

internal class DocumentStoreHolder
{ 
    private static Lazy<IDocumentStore> store = new Lazy<IDocumentStore>(CreateStore); 

    public static IDocumentStore Store => store.Value; 

    private static IDocumentStore CreateStore() 
    { 
        var serverOptions = new ServerOptions() 
        { 
            ServerUrl = "http://127.0.0.1:60956/", 
        }; 

        EmbeddedServer.Instance.StartServer(serverOptions); 

        return EmbeddedServer.Instance.GetDocumentStore("MyRavenDBStore"); 
    }
}
Enter fullscreen mode Exit fullscreen mode

g) And that’s it πŸ™‚

The post RavenDB embedded with ASP NET Core web API appeared first on Blog IT.

Top comments (0)