Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            SeedDb.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider).Wait();

            app.UseCors(builder =>
                        builder.AllowAnyOrigin() //TODO
                        );

            app.UseAuthentication();
            app.UseHttpsRedirection();
            app.UseMvc();


            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint(url: String.Format("/swagger/{0}/swagger.json", "JWTUygulamasiWebAPI-Swagger"), name: "Version CoreSwaggerWebAPI-1");
                //c.DocExpansion(DocExpansion.None);
            });
        }
Esempio n. 2
0
        public DependencySetupFixture()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddDbContext <BankIssuerDbContext>(options => options.UseInMemoryDatabase("BankIssuer"));

            var options = new DbContextOptionsBuilder <BankIssuerDbContext>()
                          .UseInMemoryDatabase(databaseName: "BankIssuer")
                          .Options;

            using var context = new BankIssuerDbContext(options);
            context.Database.EnsureCreated();
            SeedDb.Initialize(context);

            serviceCollection.AddScoped(typeof(IRepository <>), typeof(Repository <>));

            serviceCollection.AddTransient <Master>();
            serviceCollection.AddTransient <Visa>();

            serviceCollection.AddTransient <Func <Origin, ICalculator> >(serviceProvider => key =>
            {
                return(key switch
                {
                    Origin.MASTER => serviceProvider.GetService <Master>(),
                    Origin.VISA => serviceProvider.GetService <Visa>(),
                    _ => throw new KeyNotFoundException()
                });
            });
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

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

                try
                {
                    var context = services.GetRequiredService <IssueTrackerContext>();
                    context.Database.Migrate();

                    // requires using Microsoft.Extensions.Configuration;
                    // Set password with the Secret Manager tool.
                    // dotnet user-secrets set SeedUserPW <pw>

                    var testUserPw = "!XtremaxProject123";

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

            host.Run();
        }
Esempio n. 4
0
        public AccountAPITest()
        {
            var options = new DbContextOptionsBuilder <BankIssuerDbContext>()
                          .UseInMemoryDatabase(databaseName: "BankIssuer")
                          .Options;

            using var context = new BankIssuerDbContext(options);
            context.Database.EnsureCreated();
            SeedDb.Initialize(context);
        }
Esempio n. 5
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, EfCoreSampleDbContext context)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     app.UseMvc();
     app.EnsureContextMigrated <EfCoreSampleDbContext>();
     //TODO change this seed method, remove EfCoreSampleDbContext from configure method
     SeedDb.Initialize(context);//ContextSeed.SeedAsync(app).Wait();
 }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseHangfireDashboard();

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();
            app.UseCors(builder => builder
                        .AllowAnyOrigin()
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowCredentials()
                        );
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            SeedDb.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider);

            app.UseAuthentication();

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                //3. Get the instance of BoardGamesDBContext in our services layer
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <BankIssuerDbContext>();

                //4. Call the DataGenerator to create sample data
                SeedDb.Initialize(context);
            }

            host.Run();
        }
Esempio n. 8
0
 private static void RunSeeding(IHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             SeedDb.Initialize(services).Wait();
         }
         catch (Exception ex)
         {
             var logger = services.GetRequiredService <ILogger <Program> >();
             logger.LogError(ex, "An error occurred seeding the DB.");
         }
     }
 }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            // Instantiating the in-memory DB.
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <EzraAssessmentDbContext>();

                SeedDb.Initialize(services);
            }

            AutoMapperConfig.Init();

            host.Run();
        }
Esempio n. 10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, EfCoreSampleDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("./swagger/v1/swagger.json", "My API V1");
                c.RoutePrefix = string.Empty;
            });

            app.UseMvc();
            app.EnsureContextMigrated <EfCoreSampleDbContext>();
            SeedDb.Initialize(context);
        }
Esempio n. 11
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();


            var scopeFactory = host.Services.GetRequiredService <IServiceScopeFactory>();

            using (var scope = scopeFactory.CreateScope())
            {
                var db = scope.ServiceProvider.GetRequiredService <AppDbContext>();
                if (db.Database.EnsureCreated())
                {
                    SeedDb.Initialize(db);
                }
            }

            host.Run();
        }
Esempio n. 12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            SeedDb.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider);

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "NET5.JWT.CustomUser v1"));

                context.Database.EnsureCreated();
                SeedDb.Initialize(context).Wait();
            }

            app.UseRouting();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 14
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services    = scope.ServiceProvider;
                var context     = services.GetRequiredService <ApplicationDbContext>();
                var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                try
                {
                    SeedDb.Initialize(context, userManager, roleManager).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }
Esempio n. 15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WebDbContext webDbContext, IServiceProvider serviceProvider)
        {
            webDbContext.Database.EnsureCreated();
            SeedDb.Initialize(serviceProvider);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TestWebApi v1"));
            }
            SeedDb.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider);
            app.UseHttpsRedirection();

            app.UseRouting();

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

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

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Esempio n. 16
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddServerSideBlazor();
            services.AddControllersWithViews().AddCoreXF(services, this.Configuration);

            services.AddDbContext <UsersDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores <UsersDbContext>()
            .AddDefaultTokenProviders();

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.SaveToken                 = true;
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuer   = true,
                    ValidateAudience = true,
                    ValidAudience    = "https://codesolidi.com",
                    ValidIssuer      = "https://www.codesolidi.com",
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("7S79jvOkEdwoRqHx"))
                };
            });

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <SwaggerSelector>(_ => SwaggerSelector.Service);

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(setup =>
            {
                setup.DocInclusionPredicate((name, x) =>
                {
                    var provider = services.BuildServiceProvider();
                    var selector = provider.GetRequiredService <SwaggerSelector>();
                    return(selector.IncludeDocument(x));
                });

                setup.SwaggerDoc(name: "v3", new OpenApiInfo
                {
                    Title   = "CoreXF APIs",
                    Version = "v3",
                });

                setup.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    In          = ParameterLocation.Header,
                    Description = "Please insert JWT with Bearer into field",
                    Name        = "Authorization",
                    Type        = SecuritySchemeType.ApiKey
                });

                setup.AddSecurityRequirement(new OpenApiSecurityRequirement {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        },
                        new string[] { }
                    }
                });
            });

            SeedDb.Initialize(services.BuildServiceProvider());
        }