Example #1
0
        private static async Task StartSeedAsync(AntlContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole <int> > roleManager)
        {
            var applicationUserList = new ApplicationUserSeed().SeedUsers();

            if (applicationUserList == null)
            {
                throw new ArgumentNullException();
            }

            await IdentitySeed.SetIdentityRoleAsync(userManager, roleManager, applicationUserList).ConfigureAwait(false);

            var events = new EventSeed().SeedEvents(applicationUserList);

            if (events == null)
            {
                throw new ArgumentNullException();
            }

            foreach (var appointment in events)
            {
                await context.Events.AddAsync(appointment).ConfigureAwait(false);
            }

            var group = new UserGroupSeed().SeedGroups(applicationUserList);

            await context.Groups.AddAsync(group).ConfigureAwait(false);

            var friendships = new FriendshipSeed().SeedFriendShips(applicationUserList[0], applicationUserList[1]);

            await context.Friendships.AddAsync(friendships).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Example #2
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var context  = services.GetRequiredService <UserContext>();
                    var context2 = services.GetRequiredService <VariableContext>();
                    var context3 = services.GetRequiredService <EventContext>();

                    context.Database.Migrate();
                    context2.Database.Migrate();
                    context3.Database.Migrate();

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

            host.Run();
        }
Example #3
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();
        }
Example #4
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();
        }
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <EventContext>();
                EventSeed.SeedAsync(context).Wait();
            }
            host.Run();
        }
Example #6
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();
        }
Example #7
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();
        }
Example #8
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();
        }
        public static void Main(string[] args)
        {
            //building the host
            var host = CreateHostBuilder(args).Build();

            //we are calling our seed class here because of the sql server it is up and running we dono when it will start to call in start up file
            // to check whether the context is up and running so we are writing using method here
            using (var scope = host.Services.CreateScope())
            {
                //providing that which service provider it is, here it is catalog context is the service provider
                var serviceproviders = scope.ServiceProvider;
                //this line is basically saying that service provider can you tell me eventcontext is up and running.
                var context = serviceproviders.GetRequiredService <EventContext>();
                //if my db is available and up and running then call the seed method here.
                EventSeed.OnSeed(context);
            }
            host.Run();
        }
Example #10
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();
        }
Example #11
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserSeed userSeed, RoleSeed roleSeed, LevelSeed levelSeed, EnvironmentSeed environmentSeed, LogSeed logSeed, EventSeed eventSeed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                userSeed.Populate();
                roleSeed.Populate();
                levelSeed.Populate();
                environmentSeed.Populate();
                logSeed.Populate();
                eventSeed.Populate();
            }

            app.UseSwaggerSetup();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors(c =>
            {
                c.AllowAnyHeader();
                c.AllowAnyMethod();
                c.AllowAnyOrigin();
            });

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }