This is a little example how to configure step by step RavenDB with ASP MVC in base of the first reference at the end of the post.
So how we know RavenDB is a NoSQL database base on Document database and RavenDB can run in one of two modes to connecting to data store:
A client/server mode, where communication is made via HTTP;
An embedded mode, in which the client API makes direct calls against the Database API.
In this case I will use the embedded mode, also I’m using Visual Studio 2013 and ASP MVC 5, You need to Run Visual Studio as Administrator.
So the first thing that we have to do is create a Empty ASP MVC project without Authentication
Then we need to install the RavenDB package using
This will be installed all that we need to start to work, so now we need to create a ControllerFactory,
by default ASP MVC uses DefaultControllerFactory class for creating controller after receiving request from Route Handler.
This diagrams shows the request processing:
So our ControllerFactory should be like this:
so every new controller that we will create we need to set here, but why we need the ControllerFactory? In this case we need to pass the
EmbeddableDocumentStore that’s a class to inherits from DocumentStore that contains all methods to initialize the same.
So now we need to create a class to initialize our Storage File and pass this Storage File to our Controller Factory
now we need to initialize this class on our Project in the void Application_Start() in Global.asax like this
now we need to add the connection string into our web.config, so below of add this
with all this, a file called RavenDB will be generated automatically and this basically will be our storage, we can create our
RavenController like this:
so now we are ready to create our controller actions, but first, we can create our Model, for example:
now our controller need to inherit from RavenController to pass the IDocument Store, and our controller should be like this
so finally we just need to create our views in base to our Customer Model, also you can download the sourcecode here!.