示例#1
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 https://go.microsoft.com/fwlink/?LinkID=398940
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <UrlsConfig>(_configuration.GetSection("URLS"));

            // Add Health Check
            services.AddHealthChecks()
            .AddUrlGroup(
                uri: InternalEndpointsRoute.GetEndpointUri(_configuration["URLS:SampleApiUrl"],
                                                           InternalEndpointsRoute.EndpointType.HealthInfo),
                name: "SampleAPI-check",
                tags: new[] { "api" })
            .AddUrlGroup(
                uri: InternalEndpointsRoute.GetEndpointUri(_configuration["URLS:IdentityApiUrl"],
                                                           InternalEndpointsRoute.EndpointType.HealthInfo),
                name: "IdentityAPI-check",
                tags: new[] { "api" });

            // Add MVC
            services
            .AddCustomMvc(_configuration)
            .AddApplicationServices(_configuration);

            // Add Web Components
            services.AddNukaWeb(_configuration);

            // Add Controllers
            services.AddControllers();

            // Add Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultScheme          = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.Audience  = "sample.aggregator";
                options.Authority = _configuration["URLS:IdentityApiUrl"];
            });

            // Add Grpc Clients
            services.AddGrpcClient <SampleServer.SampleServerClient>()
            .ConfigureHttpClient(client => client.BaseAddress = new Uri(_configuration["URLS:SampleApiGrpcUrl"]))
            .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>()
            .AddHttpMessageHandler <HttpClientRequestDelegatingHandler>();

            // Add Jaeger Tracing
            services.AddJaegerTracing(_configuration);

            // Use Autofac container
            var containers = new ContainerBuilder();

            containers.Populate(services);

            return(new AutofacServiceProvider(containers.Build()));
        }
示例#2
0
        public static IServiceCollection AddCustomHealthCheck(
            this IServiceCollection services,
            IConfiguration configuration)
        {
            services
            .AddHealthChecks()
            .AddUrlGroup(
                uri: InternalEndpointsRoute.GetEndpointUri(configuration["URLS:IdentityApiUrl"],
                                                           InternalEndpointsRoute.EndpointType.HealthInfo),
                name: "IdentityAPI-check",
                tags: new[] { "api" })
            .AddSqlServer(
                configuration.GetConnectionString("DefaultConnection"),
                name: "SampleDB-check",
                tags: new[] { "db" }
                );

            return(services);
        }
示例#3
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 https://go.microsoft.com/fwlink/?LinkID=398940
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add Urls Configuration
            services.AddOptions();
            services.Configure <UrlsConfig>(_configuration.GetSection("URLS"));

            // Add Health Check
            services.AddHealthChecks()
            .AddUrlGroup(
                uri: InternalEndpointsRoute.GetEndpointUri(_configuration["URLS:SampleApiUrl"],
                                                           InternalEndpointsRoute.EndpointType.HealthInfo),
                name: "SampleAPI-check",
                tags: new[] { "api" })
            .AddUrlGroup(
                uri: InternalEndpointsRoute.GetEndpointUri(_configuration["URLS:IdentityApiUrl"],
                                                           InternalEndpointsRoute.EndpointType.HealthInfo),
                name: "IdentityAPI-check",
                tags: new[] { "api" });

            // Add MVC
            services.AddMvc()
            .AddNewtonsoftJson();

            // Add Web Components
            services.AddNukaWeb(_configuration);

            // Add Services
            services.AddSingleton <SampleService>();

            // Add Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddOpenIdConnect(options =>
            {
                options.SignInScheme                  = CookieAuthenticationDefaults.AuthenticationScheme;
                options.Authority                     = _configuration["URLS:IdentityApiUrl"];
                options.RequireHttpsMetadata          = true;
                options.ClientId                      = "mvc_web";
                options.ClientSecret                  = "mvc_secret";
                options.ResponseType                  = OpenIdConnectResponseType.CodeIdTokenToken;
                options.SignedOutRedirectUri          = _configuration["URLS:CallBackUrl"];
                options.SaveTokens                    = true;
                options.GetClaimsFromUserInfoEndpoint = true;
                options.Scope.Add("sample.aggregator.access");
                options.Scope.Add("sample.api.access");
                options.TokenValidationParameters.ClockSkew = TimeSpan.FromSeconds(0);
            });

            // Add HttpContext
            services.AddHttpContextAccessor();
            // Add Refits
            services.AddRefitClient <ISampleApi>()
            .ConfigureHttpClient(client => { client.BaseAddress = new Uri(_configuration["URLS:SampleApiUrl"]); })
            .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>()
            .AddHttpMessageHandler <HttpClientRequestDelegatingHandler>();

            // Add Jaeger Tracing
            services.AddJaegerTracing(_configuration);

            var containers = new ContainerBuilder();

            containers.Populate(services);

            return(new AutofacServiceProvider(containers.Build()));
        }