Example #1
0
        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();
 }
Example #3
0
 public BookRepository(IDbFactory dbFactory)
 {
     dbContext = dbFactory.Init();
 }
Example #4
0
 public PublicLibraryContext Init()
 {
     return(dbContext ?? (dbContext = new PublicLibraryContext(_options)));
 }