protected void Application_Start() { /***Example of using Antler with StructureMap container & MongoDb . See connection string below***/ ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new BlogViewEngine()); AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); var service = new BlogService(); var container = new Container(x => { x.For <IBlogService>().Use <BlogService>().Singleton(); x.Scan(s => { s.AddAllTypesOf(typeof(BaseController)); s.Assembly("Blog.Web.Common"); }); }); AntlerConfigurator = new AntlerConfigurator(); AntlerConfigurator.UseStructureMapContainer(container) .UseStorage(MongoDbStorage.Use("mongodb://localhost:27017", "Antler") .WithRecreatedDatabase(true).WithIdentityGenerator(() => new Random().Next(Int32.MinValue, Int32.MaxValue))).CreateInitialData(container.GetInstance <IBlogService>()); ControllerBuilder.Current.SetControllerFactory(new BlogControllerFactory(t => Activator.CreateInstance(t, service))); }
static HomeController() { string exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string configPath = $"{exePath}/config.json"; config = Config.Load(configPath); storage = new MongoDbStorage(config.MongoDbStorageConfig); }
public void should_not_fail() { //act var configurator = new AntlerConfigurator(); configurator.UseBuiltInContainer() .UseStorage(MongoDbStorage.Use("mongodb://localhost:27017", "AntlerTest") .WithRecreatedDatabase(true)); }
public void SetUp() { Configurator = new AntlerConfigurator(); Configurator.UseWindsorContainer() .UseStorage(MongoDbStorage.Use("mongodb://localhost:27017", "AntlerTest") .WithRecreatedDatabase(true) .WithIdentityGenerator(() => new Random().Next(1, int.MaxValue)) .WithEnsuredIndexes(MongoDbIndexBuilder.Add <Employee>(IndexKeys <Employee> .Ascending(_ => _.Id), IndexOptions <Employee> .SetUnique(true)) .ThenAdd <Team>(IndexKeys <Team> .Ascending(_ => _.Id), IndexOptions <Employee> .SetUnique(true)))); }
/// <summary> /// Drop database for MongoDb storage. /// </summary> /// <param name="storage">The storage to drop schema for.</param> public static void DropDatabase(this MongoDbStorage storage) { var url = new MongoDB.Driver.MongoUrl(TestConfig.Current.MongoDbConnectionString); storage.GetClient().DropDatabase(url.DatabaseName); }
public void TestSave() { var storg = new MongoDbStorage("farm", "test_collection", "mongodb://*****:*****@farm-shard-00-00-ivztf.mongodb.net:27017,farm-shard-00-01-ivztf.mongodb.net:27017,farm-shard-00-02-ivztf.mongodb.net:27017/farm?ssl=true&replicaSet=farm-shard-0&authSource=admin"); storg.Save(@"{ ""field"" : ""value"" }"); }
/// <summary> /// Drop database for MongoDb storage. /// </summary> /// <param name="storage">The storage to drop schema for.</param> public static void DropDatabase(this MongoDbStorage storage) { storage.GetClient().DropDatabase("MiniProfiler"); }