示例#1
0
        public static void Main(string[] args)
        {
            //BuildWebHost(args).Run();

            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var UserContext = services.GetRequiredService <UserContext>();
                    UserDbInitializer.Initialize(UserContext);

                    var OrderContext = services.GetRequiredService <OrderContext>();
                    OrderDbInitializer.Initialize(OrderContext, UserContext);

                    //var ReviewContext = services.GetRequiredService<ReviewContext>();
                    //ReviewDbInitializer.Initialize(ReviewContext);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
示例#2
0
        public OrderService(IOrderContext orderContext, OrderContext seedContext, IMapper mapper)
        {
            _orderContext = orderContext;
            _mapper       = mapper;

            // Only for seeding.
            OrderDbInitializer.Initialize(seedContext);
        }
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services       = scope.ServiceProvider;
                var dbRoadFreights = services.GetRequiredService <RoadFreightDbContext>();
                RoadFreightDbInitializer.Initialize(dbRoadFreights);
                var dbSeaFreights = services.GetRequiredService <SeaFreightDbContext>();
                SeaFreightDbInitializer.Initialize(dbSeaFreights);
                var dbAirFreights = services.GetRequiredService <AirFreightDbContext>();
                AirFreightDbInitializer.Initialize(dbAirFreights);
                var dbOrders = services.GetRequiredService <OrderDbContext>();
                OrderDbInitializer.Initialize(dbOrders);
            }

            host.Run();
        }