Last active
December 20, 2015 06:58
-
-
Save ritasker/6089473 to your computer and use it in GitHub Desktop.
The Custom Bootstrapper from my first Nancy FX app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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