Пример #1
0
        public void Setup()
        {
            var dbContext = new AppDbContext(new DbContextOptionsBuilder <AppDbContext>()
                                             .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                             .Options);

            AppDbContextInitializer.Initialize(dbContext);

            _uow = new AppUnitOfWork(dbContext);
        }
        public static void Main(string[] args)
        {
            var services = new ServiceCollection();

            services.AddTransient <Demo>();
            services.RegisterConfiguration().AddInfrastructure();

            var serviceProvider = services.BuildServiceProvider();

            using (var appDbContext = serviceProvider.GetRequiredService <AppDbContext>())
            {
                AppDbContextInitializer.Initialize(appDbContext);
            }

            serviceProvider.GetRequiredService <Demo>().Start();
        }
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            // Add Default Data In DB
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var context = services.GetRequiredService <AppDbContext>();
                    AppDbContextInitializer.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }