public static void Initialize(IServiceProvider serviceProvider) { using (var context = new PublicLibraryContext(serviceProvider .GetRequiredService < DbContextOptions <PublicLibraryContext> >())) { if (context.Books.Any()) { return; } context.Books.AddRange( new Models.Book { Name = "Sapiens", AuthorName = "Yuval Noah Harari" }, new Models.Book { Name = "L'etranger", AuthorName = "Albert Camus" }); context.SaveChanges(); } }
public FormRepository(IDbFactory dbFactory) { dbContext = dbFactory.Init(); }
public BookRepository(IDbFactory dbFactory) { dbContext = dbFactory.Init(); }
public PublicLibraryContext Init() { return(dbContext ?? (dbContext = new PublicLibraryContext(_options))); }