In my last post about RavenDB, it shows how to configure RavenDB with ASP MVC on embedded mode, creating a RavenController and ControllerFactory.
Now I will show how to configure with client/server mode, also in this time I will use DI and Unity as IoC to properly access RavenDB in a Business layer.
So basically my structure of the solution it this:
MvcRavenDBSample.Web -> My MVC project
MvcRavenDBSample.Data -> My Services and Repositories
MvcRavenDBSample.Domain -> My Models
So we can start with our MvcRavenDBSample.Domain class project
MvcRavenDBSample.Domain
In this project we should only put our models, in my case I created a folder call Models,
but you can order your domain as you like, actually Uncle Bob is writing a book call “Clean Architecture”
for how to create an properly architecture in one solution.
So this is my dummy model
now we can pass to our MvcRavenDBSample.Data class project
MvcRavenDBSample.Data
So in this project we should have the RavenDB Client. So we can start to install the RavenDB Client by nuget package.
Now we can create our Repositories Services
so as you can see I pass in the constructor the url to connect to RavenDB in client/server mode. So now
we can pass to our MVC project.
MvcRavenDBSample.Web
So in my case I like to use Unity for IoC, but you can use Structure Map, Ninject, etc..
So in our container we add the Service and pass the url that connect with our RavenDB Server
and now we can create our CustomerController
As you can see our actions are really clean and easy to test. So finally we just need initialize the RavenDB Server, you can download from here!.
Once you downloaded, you can start the Raven Service by executing /server/raven.server.exe, and then you can then visit
http://localhost:8080 for looking at the UI. By default is using the port :8080
Once the Raven service is up, compile and done. You can download the source code from here!.
Also we can add a User and Password to access to the RavenDB that I will write in the next post,
so hope this helps and I’m sorry for my terrible English =)