예제 #1
0
        public static void Main(string[] args)
        {
            //It creates the hostmachine
            //We are asking host to build the containers, When you start this project.
            //so after the successful build we need to seed the data
            var host = CreateHostBuilder(args).Build();

            //Now lets call the host and ask for the services.
            //CreateScope() mean get me the access to all the services that are available with in my host.
            //scope is a huge memory variable.
            using (var scope = host.Services.CreateScope())
            {
                //The variable scope is wrapped by "using" statement
                //What ever we write the code inside this, is the only code that can use this varible "scope"
                //the scope of the varible is limited in this using block.

                /*WHat is the purpose of using statement??  It guarantee that WHen you get out of this curly brackets
                 * It is going to destroy scope variable, which means your memory will be released*/

                /*Now we can ask the scope that, can you tell me all the service providers ,that is available
                 * for each scope*/
                var serviceProviders = scope.ServiceProvider;//we are getting all the serviceproviders

                /*Out of those service providers, can you get the acces to this requiredService which is
                 * provided by catalog context*/
                var context = serviceProviders.GetRequiredService <EventContext>();

                //Now we know that database is created
                //we can now call the seed
                EventSeed.Seed(context);
            }
            host.Run();
        }
예제 #2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope()) {
                var serviceProviders = scope.ServiceProvider;
                var context          = serviceProviders.GetRequiredService <EventContext>();
                EventSeed.Seed(context);
            }
            host.Run();
        }
예제 #3
0
        public static void Main(string[] args)
        {
            //Seeds data only after the server is up
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <EventContext>();
                EventSeed.Seed(context);
            }
            host.Run();
        }
예제 #4
0
        public static void Main(string[] args)
        {
            //here we split up the .Build.Run so that the database is seeded
            //before it is available to the user
            var host = CreateHostBuilder(args).Build();


            using (var scope = host.Services.CreateScope())
            {
                var serviceProviders = scope.ServiceProvider;
                var context          = serviceProviders.GetRequiredService <EventContext>();
                EventSeed.Seed(context);
            }
            host.Run();
        }
예제 #5
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build(); //builds a vm

            //using is overloaded for memory destruction after it is used
            using (var scope = host.Services.CreateScope()) // give me all the services
            {                                               //look for host m/c. within that looking for services within scope, within scope, look for context
                var services = scope.ServiceProvider;       // all services in scope catalog db context
                //get me required service with name EventContext
                var context =
                    services.GetRequiredService <EventContext>();
                EventSeed.Seed(context);
            }
            host.Run();
        }
예제 #6
0
        public static void Main(string[] args)
        {
            //Below code we are storing the host details into host variable
            var host = CreateHostBuilder(args).Build();

            //The below using keyword is used to dispose the object out of memory as soon as the scope is done helps with memory mgmt
            using  (var scope = host.Services.CreateScope())
            {
                //Below code gets all service provides from the startup
                var serviceProviders = scope.ServiceProvider;
                //Below line is to get the DB service provider details from the startup
                var context = serviceProviders.GetRequiredService <EventContext>();
                //At this point I know the host machine is created
                EventSeed.Seed(context);
            }

            host.Run();
        }