Esempio n. 1
0
        public static void AddWebApiProxy(this IServiceCollection services, Action <WebApiProxyOptions> optionAction)
        {
            var option = new WebApiProxyOptions();

            optionAction(option);

            var webClient = new HttpApiClient();

            foreach (var o in option.ProxyOptions)
            {
                var types = o.GetType().Assembly.GetTypes().Where(x => x.IsInterface);
                foreach (var t in types)
                {
                    services.AddScoped(t, x => webClient.GetHttpApi(t, o.BaseUrl));
                }
            }
        }
Esempio n. 2
0
        public static IShriekBuilder AddWebApiProxy(this IShriekBuilder builder, Action <WebApiProxyOptions> optionAction)
        {
            var option = new WebApiProxyOptions();

            optionAction(option);

            var webClient = new HttpApiClient();

            foreach (var o in option.WebApiProxies)
            {
                var types = o.GetType().Assembly.GetTypes().Where(x =>
                                                                  x.IsInterface && x.GetMethods().SelectMany(m => m.GetCustomAttributes(typeof(ApiActionAttribute), true)).Any());
                foreach (var t in types)
                {
                    builder.Services.AddScoped(t, x => webClient.GetHttpApi(t, o.BaseUrl));
                }
            }

            return(builder);
        }