public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); try { var context = services.GetRequiredService <BookSearchContext>(); DbInitializer.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "Произошла ошибка при создании БД."); } } host.Run(); CreateHostBuilder(args).Build().Run(); var kernel = new StandardKernel(new NinjectRegistration(), new ServiceModule("BookSearchContext")); IDbCRUD crudServ = kernel.Get <IDbCRUD>(); }
public BooksController(IDbCRUD dbCrud, IWebHostEnvironment appEnvironment, ILogger <BooksController> logger) { _appEnvironment = appEnvironment; _dbCrud = dbCrud; _logger = logger; }
public BookingController() { dbCrud = new DbBooking(); }
//You can easily switch between ADO implementation and EF implementation because they share //the same interface public BookingController() { // dbCrud = new DbBooking(); dbCrud = new DbBookingEntityFramework(); }
public CrudBuilder(TDbContext dbContext) { _dbCRUD = new DbCRUD <TDbContext>(dbContext); }