ConfigureServices() public static method

public static ConfigureServices ( IMvcBuilder mvcBuilder ) : void
mvcBuilder IMvcBuilder
return void
示例#1
0
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration
     .ConfigureServices(services)
     .AddOpenApi()
     .AddDbContext(configuration);
 }
示例#2
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services) =>
 ApiConfiguration.ConfigureServices(services, Environment)
 .AddCustomServices()
 .AddOpenApi()
 .AddCors(options => options.AddPolicy("CorsApi",
                                       builder => builder.WithOrigins(
                                           "http://localhost:4200",
                                           "http://localhost:3000",
                                           "http://localhost:8080")
                                       .AllowAnyHeader().AllowAnyMethod()))
 .AddEntityFrameworkCore(Configuration)
 .AddMediatr()
 .AddOpenTelemetryTracing(builder => builder
                          .AddAspNetCoreInstrumentation()
                          .AddHttpClientInstrumentation()
                          .AddJaegerExporter()
                          .AddZipkinExporter()
                          )
 .AddCustomHealthChecks(Configuration)
 .AddHashids(setup => {
     setup.Salt          = "your_salt";
     setup.MinHashLength = 16;
 })
 .AddSwaggerGen(c => c.OperationFilter <HashIdsOperationFilter>())
 .AddResponseCompression()
 ;
示例#3
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration.ConfigureServices(services)
     .AddCors()
     .AddDbContext <ShopContext>(options =>
     {
         options.UseSqlServer(@"Server=.;Database=Shop;Trusted_Connection=True;");
     });
 }
示例#4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Register Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = TestServerAuthenticationDefaults.AuthenticationScheme;
            })
            .AddTestServerAuthentication();

            ApiConfiguration.ConfigureServices(services);
        }
示例#5
0
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration.ConfigureServices(services)
     .AddDbContext <NotesContext>(options =>
     {
         options.UseSqlServer(configuration.GetConnectionString(Constants.SqlServer), sqlOptions =>
         {
             sqlOptions.MigrationsAssembly(typeof(TestStartup).Assembly.FullName);
         });
     });
 }
示例#6
0
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration.ConfigureServices(services)
     .AddDbContextPool <ApiDbContext>(options =>
     {
         options.UseSqlServer(Configuration.GetConnectionString("SqlServer"), sqlOptions =>
         {
             sqlOptions.MigrationsAssembly(typeof(Startup).Assembly.GetName().Name);
         });
     })
     .AddControllers();
 }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Register Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.Authority = "https://localhost:8000";
            });

            ApiConfiguration.ConfigureServices(services);
        }
示例#8
0
        public void ConfigureServices(IServiceCollection services)
        {
            ApiConfiguration.ConfigureServices(services);
            services
            .AddAuthentication(TestServerDefaults.AuthenticationScheme)
            .AddTestServer();

            services
            .AddDbContext <ShopContext>(options =>
            {
                // appsettings.json, Copy to Output Directory: Copy if newer
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
            });
        }
示例#9
0
    public void ConfigureServices(IServiceCollection services)
    {
        // Register Authentication
        services.AddAuthentication(options =>
        {
            options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
        })
        .AddJwtBearer(options =>
        {
            options.Authority = "https://localhost:5001";
        });

        var mvcBuilder = services.AddControllers();

        ApiConfiguration.ConfigureServices(mvcBuilder);
    }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Register Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = TestServerDefaults.AuthenticationScheme;
            })
            .AddTestServer()
            // We can register as many TestServer authentication options with different scheme names
            .AddTestServer("bearer", options =>
            {
                options.NameClaimType = "name";
                options.RoleClaimType = "role";
            })
            .AddTestServer("extra");

            ApiConfiguration.ConfigureServices(services);
        }
示例#11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Register Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = TestServerDefaults.AuthenticationScheme;
            })
            .AddTestServer()
            // We can register as many TestServer authentication options with different scheme names
            .AddTestServer("bearer", options =>
            {
                options.NameClaimType = "name";
                options.RoleClaimType = "role";
            })
            .AddTestServer("extra");

            var mvcBuilder = services.AddControllers()
                             .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            ApiConfiguration.ConfigureServices(mvcBuilder);
        }
示例#12
0
        public void ConfigureServices(IServiceCollection services)
        {
            ApiConfiguration.ConfigureServices(services, Configuration, Environment);
            services.AddDistributedMemoryCache();
            services.AddOpenApi();

            var origins = new string[] { "http://localhost:4200", "https://localhost:4200", "http://localhost:3000" };

            services.AddCors(options =>
            {
                options.AddPolicy(AllowedOrigins,
                                  builder =>
                {
                    builder.WithOrigins(origins)
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.AddEntityFrameworkCore(Configuration)
            .AddCustomDbContext(Configuration);
        }
示例#13
0
        public void ConfigureServices(IServiceCollection services)
        {
            ApiConfiguration.ConfigureServices(services, _configuration, _hostEnvironment)
            .AddDistributedMemoryCache()
            .RegisterSwaggerExtensions(ApiConstants.ApiTitleV1, ApiConstants.ApiVersionV1)
            .AddCors(options => options.AddPolicy(AllowedOriginsPolicy, corsbuilder =>
            {
                var allowedOrigins =
                    _configuration.GetSection <Cors>().AllowedOrigins?.Split(";") ??
                    throw new ArgumentNullException(AllowedOriginsPolicy);
                corsbuilder.AllowAnyOrigin()
                .AllowAnyHeader()
                .AllowAnyMethod()
                .WithOrigins(allowedOrigins);
            }))
            .AddControllers();

            if (IsOnlyApi())
            {
                return;
            }
            services.AddSpaStaticFiles(configuration => configuration.RootPath = SpaStaticsPath);
        }
示例#14
0
 // This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration.ConfigureServices(services);
 }
示例#15
0
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration.ConfigureServices(services)
     .AddAuthentication(TestServerAuthenticationDefaults.AuthenticationScheme)
     .AddTestServerAuthentication();
 }
示例#16
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration.ConfigureServices(services)
     .AddAuthentication()
     .AddJwtBearer();
 }
示例#17
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration.ConfigureServices(services, Environment, Configuration);
 }
示例#18
0
 public void ConfigureServices(IServiceCollection services)
 {
     ApiConfiguration.ConfigureServices(services, _configuration, _hostingEnvironment)
     .AddAuthentication(options => options.DefaultScheme = TestServerDefaults.AuthenticationScheme)
     .AddTestServer();
 }