protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); Bootstrapper.Initialize(); var profile = new AutoMapperProfile(); Mapper.AddProfile(profile); Mapper.AssertConfigurationIsValid(profile.ProfileName); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; Database.SetInitializer<SketchDbContext>(null); Database.SetInitializer<EventStoreDbContext>(null); using (var sketchDbContext = new SketchDbContext()) using (var eventStoreDbContext = new EventStoreDbContext()) { if (sketchDbContext.Database.CreateIfNotExists()) { eventStoreDbContext.Database.ExecuteSqlCommand(((IObjectContextAdapter)eventStoreDbContext).ObjectContext.CreateDatabaseScript()); } } }
private static void Initialize() { var profile = new AutoMapperProfile(); Mapper.AddProfile(profile); Mapper.AssertConfigurationIsValid(profile.ProfileName); Database.DefaultConnectionFactory = new ConnectionFactory(Database.DefaultConnectionFactory); Database.SetInitializer<SketchDbContext>(null); Database.SetInitializer<EventStoreDbContext>(null); using (var sketchDbContext = new SketchDbContext()) using (var eventStoreDbContext = new EventStoreDbContext()) { if (!sketchDbContext.Database.Exists()) { ((IObjectContextAdapter)sketchDbContext).ObjectContext.CreateDatabase(); eventStoreDbContext.Database.ExecuteSqlCommand(((IObjectContextAdapter)eventStoreDbContext).ObjectContext.CreateDatabaseScript()); } } var container = new UnityContainer(); var unityServiceLocator = new UnityServiceLocator(container); Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => unityServiceLocator); ServiceLocator = Microsoft.Practices.ServiceLocation.ServiceLocator.Current; new Core.Module().Init(container); new Module().Init(container); }