Refactored to support RavenDb Embedded or IIS mode.