public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IDetachedContext <DefaultContext> detached) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // ensure db exists and add data from Seed.json if (detached.DbContext.Database.EnsureCreated()) { detached.SeedFromJsonFileAsync("./Server/Seed.json").GetAwaiter().GetResult(); } // add localization support CultureInfo[] supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("es-AR") }; app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture(supportedCultures[0], supportedCultures[0]), FallBackToParentCultures = false, SupportedCultures = supportedCultures, SupportedUICultures = supportedCultures }); // configure WebPack hot reload and error page if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, ConfigFile = "webpack.config.js" }); } else { app.UseExceptionHandler("/Home/Error"); } // use Angular2 client files (.js, .html) app.UseStaticFiles(); // use MVC with SPA fallback to support Angular2 routing app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); }
public static async Task SeedFromJsonFileAsync(this IDetachedContext context, string filePath, bool identityInsert = true) { string json = File.ReadAllText(filePath); JObject jsonRoot = (JObject)JsonConvert.DeserializeObject(json); foreach (var jsonCatalog in jsonRoot.Properties()) { IDetachedSet set = context.Set(jsonCatalog.Name); // insert objects (detached roots), one by one. foreach (var jsonEntity in jsonCatalog.Values()) { object entity = jsonEntity.ToObject(set.EntityType); await set.UpdateAsync(entity); } IEntityType entityType = context.DbContext.Model.FindEntityType(set.EntityType); if (identityInsert && HasIdentity(entityType)) { string tableName = entityType.Relational().TableName; // SQL table name. // enable identity insert. await context.DbContext.Database.OpenConnectionAsync(); await context.DbContext.Database.ExecuteSqlCommandAsync($"SET IDENTITY_INSERT [dbo].[{tableName}] ON;"); // save changes with identity insert enabled. await context.SaveChangesAsync(); await context.DbContext.Database.ExecuteSqlCommandAsync($"SET IDENTITY_INSERT [dbo].[{tableName}] OFF;"); context.DbContext.Database.CloseConnection(); } else { await context.SaveChangesAsync(); } } }
public RoleService(IDetachedContext <DefaultContext> detachedContext) : base(detachedContext) { }
public DetachedService(IDetachedContext <TDbContext> detachedContext) { _detachedContext = detachedContext; }
public void SetDetachedContext(IDetachedContext detachedContext) { _detachedContext = detachedContext; }