Google Groups

Re: [ServiceStack] ServiceStack and MongoDB

Davis May 26, 2012 9:37 PM
Posted in group: ServiceStack .NET Open Source REST Web Services Framework
Hi Demis, as I'm looking at implementing the sample code and AuthRepository, however, I've got a small issue.

The design is to have different mongo db for different session, depending on the MVC route (POC for multi-tenant).

Perhaps you can enlighten me a little on how to design the AuthRepository with dynamic database connection?

Thanks in advance.

On Tuesday, 1 May 2012 08:49:17 UTC+8, mythz wrote:
As ServiceStack's IOC isn't tied to any particular technology, getting it to work with MongoDb shouldn't be any different to what you're use to. 
Here's something IOC registration found off the InterWebs:

var connString = ConfigurationManager.AppSettings["MONGOHQ_URL"];
var databaseName = connString.Split('/').Last();
var server = MongoServer.Create(connString);
var database = server.GetDatabase(databaseName);
if (!database.CollectionExists("Messages"))

As for having it work as a ServiceStack Auth backend, it just needs to implement IUserAuthRepository, here's the OrmLite and Redis UserAuthRepo back-ends you can use for inspiration :)