Пример #1
0
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ConfigureServices();

            /// seed data
            var context    = ServiceProvider.GetRequiredService <ElectronicsStoreContext> ();
            var unitOfWork = ServiceProvider.GetRequiredService <IUnitOfWork> ();

            DataSeeds.Initialize(context, unitOfWork);
            context.SaveChanges();

            ///run forms
            var mainForm = ServiceProvider.GetRequiredService <MainForm> ();

            Application.Run(mainForm);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <ToDoListContext>();
                try
                {
                    DataSeeds.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError("An error occured seeding database.", ex);
                }
            }

            host.Run();
        }