Esempio n. 1
0
        public static void AddApiGateway(this IServiceCollection services, Action <ApiGatewayOptions> options = null)
        {
            Options = new ApiGatewayOptions();

            options?.Invoke(Options);

            var apis = new ApiOrchestrator();

            services.AddTransient <IApiOrchestrator>(x => apis);

            services.AddAuthorizationFilters()
            .AddActionFilters()
            .AddExceptionFilters()
            .AddResultFilters();

            services.AddHttpClient <IHttpService, HttpService>();

            services.AddApiGatewayResponseCaching();

            services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
        }
Esempio n. 2
0
        public static void AddApiGateway(this IServiceCollection services, Action <ApiGatewayOptions> options = null)
        {
            Options = new ApiGatewayOptions();

            options?.Invoke(Options);

            var apis = new ApiOrchestrator();

            services.AddTransient <IApiOrchestrator>(x => apis);
            services.AddScoped <GatewayAuthorizeAttribute>();
            services.AddScoped <GatewayGetOrHeadAuthorizeAttribute>();
            services.AddScoped <GatewayGetOrchestrationAuthorizeAttribute>();
            services.AddScoped <GatewayPostAuthorizeAttribute>();
            services.AddScoped <GatewayPutAuthorizeAttribute>();
            services.AddScoped <GatewayPatchAuthorizeAttribute>();
            services.AddScoped <GatewayDeleteAuthorizeAttribute>();
            services.AddHttpClient <IHttpService, HttpService>();

            if (Options != null)
            {
                if (Options.UseResponseCaching && Options.ResponseCacheSettings != null)
                {
                    services.AddResponseCaching();

                    services.AddMvc(o => o.Filters.Add(new ResponseCacheAttribute
                    {
                        NoStore          = Options.ResponseCacheSettings.NoStore,
                        Location         = Options.ResponseCacheSettings.Location,
                        Duration         = Options.ResponseCacheSettings.Duration,
                        VaryByHeader     = Options.ResponseCacheSettings.VaryByHeader,
                        VaryByQueryKeys  = Options.ResponseCacheSettings.VaryByQueryKeys,
                        CacheProfileName = Options.ResponseCacheSettings.CacheProfileName
                    }));
                }
            }

            services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
        }