Skip to content

Instantly share code, notes, and snippets.

@ritasker
Last active December 20, 2015 06:58
Show Gist options
  • Save ritasker/6089473 to your computer and use it in GitHub Desktop.
Save ritasker/6089473 to your computer and use it in GitHub Desktop.
The Custom Bootstrapper from my first Nancy FX app.
public class CustomBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
string mongoUser = ConfigurationManager.AppSettings["MongoUser"];
string mongoPassword = ConfigurationManager.AppSettings["MongoPassword"];
var connString = ConfigurationManager.AppSettings["MongoUrl"];
connString = string.Format(connString, mongoUser, mongoPassword);
var databaseName = connString.Split('/').Last();
var client = new MongoClient(connString);
var server = client.GetServer();
var database = server.GetDatabase(databaseName);
base.ConfigureApplicationContainer(container);
if (!database.CollectionExists("Comments"))
database.CreateCollection("Comments");
container.Register<MongoServer>(server);
container.Register<MongoDatabase>(database);
container.Register<MongoCollection<Comment>>(database.GetCollection<Comment>("Comments"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment