Let’s take a look at more ‘optional’ and supporting features of db4o. One of these is that you can run RavenDB in embedded mode. I personally like embed the database smaller applications. Another big selling point is that this is very nice for testing reasons.
The first thing we need to do is to reference the required assemblies. The easiest way is to grab the ‘RavenDB (embedded)’ package via NuGet. Alternatively you can reference the assemblies in ‘EmbeddedClient’ folder of the RavenDB distribution.
After than we just start up an EmbeddableDocumentStore instance. That’s all, we now can start using the embedded storage.
In Memory Instance
For testing purpose it’s often useful to create in memory database instances, which can be created and thrown away really quickly. That is possible with RavenDB. We just need to set the RunInMemory flag: BOOM, now RavenDB runs in memory.
When we run an embedded database we cannot inspect that database while the application is running. For that we need to provide access for our administration tools. Well, that’s again a flag away. When we enable the ‘UseEmbeddedHttpServer’ flag RavenDB will start up a small HTTP server which exposes the regular RavenDB functionality. Then we just can use Raven Studio (the Silverlight app which comes with RavenDB) to connect to our database.
Alternatively we can manually start the HTTP server any time when required:
When you want to ensure that the application has the rights to open the port you can use this utility to ask for permission. Basically it checks if the application has enough rights to open the port. In case it doesn’t have the rights it will prompt for it:
Now we know how to run RavenDB as embedded database. A wonderful feature, even when we use it only for testing. After this simple feature I hopefully get back to more advanced features next time. =).
- RavenDB: Preventing Database Slaughter
- World of Music: Japan, Korea, China (Beetys Blog-Parade)