My Gestalt

Understand the chaotic world by developing meaningful perception through the acquisition of seemingly disparate knowledge.

Collect information in large quantity with precise detail and connect the dots of meaning to form your own picture of the universe.

Act upon it

Knowledge and understanding without action is waste.

Be Grateful

Never underestimate the power of gratitude.


Forgiveness will make your heart happy. Forgiveness is not about someone deserving it, it's about healing your heart.

RavenDB, VB and WebAPI

What is a great combination of tools for the Modern Web Application?

Since our development language of choice here is VB.Net we need things that can work with it.

RavenDB is a great Document Database with support for VB.Net

WebAPI allows us to make Mobile-ready backends that can also be used with MVC.

Combining these three together is not exactly simple.  This Sample gives you the missing pieces to use this fantastic combination to get a VB.Net Application going.

Using StructureMap, here is the entire RavenApiController:

Imports System.Web.Http
Imports Raven.Client

Public MustInherit Class RavenAPIController
    Inherits ApiController

    Public Property DocumentSession As IDocumentSession

    Protected Sub New()
    End Sub

End Class
When you add a DocumentSession Property as above, StrucureMap is invoked like this:
'setter injection for API Controllers
                     x.OfType(Of IMembershipProvider)()
                     x.OfType(Of IOAuthProvider)()
                     x.OfType(Of IUserStore)()
                     x.OfType(Of IDocumentSession)()
                 End Sub)

And a GET Method in the WebAPI requiring Authorization looks like this:
    ''' <summary>
    ''' Return a single Id as requested
    ''' </summary>
    Public Overloads Function [Get](id As String) As Todo
            JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore

            Dim entity = DocumentSession.Load(Of Todo)(id)
            If entity Is Nothing Then
                _Responsecode = HttpStatusCode.NotFound
                Return Nothing
                If member Is Nothing OrElse entity.Owner.href <> member.Id Then
                    _Responsecode = HttpStatusCode.Unauthorized
                End If
                Return Nothing
            End If
            Return entity
        Catch ex As Exception
            'log exception
            Return Nothing
        End Try
    End Function

A full Blog Article describing the usage and the Source are available by request.