Beispiel #1
0
        public void TestMethod_Autofac()
        {
            ContainerBuilder containerBuilder = new ContainerBuilder();

            IFeignBuilder feignBuilder = containerBuilder.AddFeignClients(options =>
            {
                options.Assemblies.Add(typeof(ITestService).Assembly);
                options.FeignClientPipeline.ReceivingQueryResult();
            });

            IContainer container = containerBuilder.Build();

            using (ILifetimeScope lifetimeScope = container.BeginLifetimeScope())
            {
                ITestService testService = lifetimeScope.Resolve <ITestService>();
                var          result      = testService.GetQueryResultValue("1", null);
            }
        }
 protected static void AddTestFeignClients(IFeignBuilder feignBuilder)
 {
     //feignBuilder.Options.Lifetime = FeignClientLifetime.Transient;
     //feignBuilder.AddFeignClients(this.GetType().Assembly, feignBuilder.Options.Lifetime);
 }
Beispiel #3
0
 public static IFeignBuilder AddServiceDiscovery <T>(this IFeignBuilder feignBuilder) where T : class, IServiceDiscovery
 {
     feignBuilder.Services.TryAddSingleton <IServiceDiscovery, T>();
     return(feignBuilder);
 }
Beispiel #4
0
 public static IFeignBuilder AddServiceDiscovery(this IFeignBuilder feignBuilder, IServiceDiscovery serviceDiscovery)
 {
     feignBuilder.Services.TryAddSingleton(serviceDiscovery);
     return(feignBuilder);
 }
Beispiel #5
0
 public static IFeignBuilder AddConverter <TSource, TResult>(this IFeignBuilder feignBuilder, IConverter <TSource, TResult> converter)
 {
     feignBuilder.Converters.AddConverter(converter);
     return(feignBuilder);
 }
 /// <summary>
 /// 添加<see cref="ICacheProvider"/>
 /// </summary>
 /// <typeparam name="TCacheProvider"></typeparam>
 /// <param name="feignBuilder"></param>
 /// <returns></returns>
 public static IFeignBuilder AddCacheProvider <TCacheProvider>(this IFeignBuilder feignBuilder) where TCacheProvider : ICacheProvider
 {
     feignBuilder.AddOrUpdateService(typeof(ICacheProvider), typeof(TCacheProvider), FeignClientLifetime.Singleton);
     return(feignBuilder);
 }
 /// <summary>
 /// 添加<see cref="IServiceDiscovery"/>
 /// </summary>
 /// <typeparam name="TServiceDiscovery"></typeparam>
 /// <param name="feignBuilder"></param>
 /// <returns></returns>
 public static IFeignBuilder AddServiceDiscovery <TServiceDiscovery>(this IFeignBuilder feignBuilder) where TServiceDiscovery : IServiceDiscovery
 {
     feignBuilder.AddOrUpdateService(typeof(IServiceDiscovery), typeof(TServiceDiscovery), FeignClientLifetime.Singleton);
     return(feignBuilder);
 }
 /// <summary>
 /// 添加<see cref="ILoggerFactory"/>
 /// </summary>
 /// <typeparam name="TLoggerFactory"></typeparam>
 /// <param name="feignBuilder"></param>
 /// <returns></returns>
 public static IFeignBuilder AddLoggerFactory <TLoggerFactory>(this IFeignBuilder feignBuilder) where TLoggerFactory : ILoggerFactory
 {
     feignBuilder.AddOrUpdateService(typeof(ILoggerFactory), typeof(TLoggerFactory), FeignClientLifetime.Singleton);
     return(feignBuilder);
 }
 public static IFeignBuilder AddDiscoveryClient(this IFeignBuilder feignBuilder)
 {
     return(feignBuilder.AddServiceDiscovery <SteeltoeServiceDiscovery>());
 }
Beispiel #10
0
        public static IFeignBuilder AddTestFeignClients(this IFeignBuilder feignBuilder)
        {
            Feign.FeignBuilderExtensions.AddConverter <TestServiceParam, string>(feignBuilder, new TestServiceParamStringConverter());
            feignBuilder.AddServiceDiscovery <TestServiceDiscovery>();
            feignBuilder.Options.IncludeMethodMetadata = true;
            Feign.FeignBuilderExtensions.AddFeignClients <IFeignBuilder>(feignBuilder, Assembly.GetExecutingAssembly(), FeignClientLifetime.Transient);
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().SendingRequest += (sender, e) =>
            {
                //e.Terminate();
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestControllerService>().SendingRequest += (sender, e) =>
            {
                //e.CancellationTokenSource.Cancel();
                //e.Terminate();
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestControllerService>().CancelRequest += (sender, e) =>
            {
                e.CancellationToken.Register(obj =>
                {
                    ICancelRequestEventArgs <ITestControllerService> ee = obj as ICancelRequestEventArgs <ITestControllerService>;
                    string s = ee.RequestMessage.ToString();
                }, e);
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().SendingRequest += (sender, e) =>
            {
                var types = feignBuilder.Options.Types;
                if (e.RequestMessage.Content != null)
                {
                    MultipartFormDataContent multipartFormDataContent = e.RequestMessage.Content as MultipartFormDataContent;
                    if (multipartFormDataContent != null)
                    {
                        string boundary = multipartFormDataContent.Headers.ContentType.Parameters.FirstOrDefault(s => s.Name == "boundary").Value;
                        boundary = boundary.Replace("\"", "");
                        multipartFormDataContent.Headers.Remove("Content-Type");
                        multipartFormDataContent.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary);
                    }
                }
            };
            feignBuilder.Options.FeignClientPipeline.FallbackRequest += (sender, e) =>
            {
                var            parameters    = e.GetParameters();
                object         fallback      = e.Fallback;
                IFallbackProxy fallbackProxy = e.FallbackProxy;
                if (fallbackProxy == null)
                {
                    string s = "";
                }
                MethodInfo method = e.Method;
                e.Terminate();
            };
            feignBuilder.Options.FeignClientPipeline.Initializing += (sender, e) =>
            {
                ((HttpClientHandler)e.HttpClient.Handler.InnerHandler).AutomaticDecompression = DecompressionMethods.None | DecompressionMethods.GZip | DecompressionMethods.Deflate;
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().Initializing += (sender, e) =>
            {
                e.FeignClient.Service.Name        = "Initializing set";
                e.FeignClient.Service.ServiceId   = e.FeignClient.ServiceId;
                e.FeignClient.Service.ServiceType = e.FeignClient.ServiceType;
            };
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").Initializing += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Disposing += (sender, e) =>
            {
                var ee = e;
            };
            //            feignBuilder.Options.FeignClientPipeline.Authorization(proxy =>
            //            {
            //#if NETSTANDARD
            //                return ("global", "asdasd");
            //#else
            //                return new AuthenticationHeaderValue("global", "asdasd");
            //#endif
            //            });
            feignBuilder.Options.FeignClientPipeline.BuildingRequest += FeignClientPipeline_BuildingRequest;
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().BuildingRequest += (sender, e) =>
            {
                IFeignClient <ITestService> feignClient = e.FeignClient as IFeignClient <ITestService>;
                ITestService service = feignClient.Service;
            };
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").BuildingRequest += (sender, e) =>
            {
                var fallbackFeignClient = e.FeignClient.AsFallback <object>();
                fallbackFeignClient = e.FeignClient.AsFallback <object>();
                fallbackFeignClient = e.FeignClient.AsFallback <ITestService>();

                var fallback = fallbackFeignClient?.Fallback;

                fallback = e.FeignClient.GetFallback <object>();
                fallback = e.FeignClient.GetFallback <object>();
                //     fallback = e.FeignClient.GetFallback<ITestService>();

                if (!e.Headers.ContainsKey("Authorization"))
                {
                    e.Headers["Authorization"] = "service asdasd";
                }
                e.Headers["Accept-Encoding"] = "gzip, deflate, br";

                //add session
                e.Headers.Add("cookie", "csrftoken=EGxYkyZeT3DxEsvYsdR5ncmzpi9pmnQx; _bl_uid=nLjRstOyqOejLv2s0xtzqs74Xsmg; courseId=1; versionId=522; textbookId=2598; Hm_lvt_f0984c42ef98965e03c60661581cd219=1559783251,1559818390,1560213044,1560396804; uuid=6a30ff68-2b7c-4cde-a355-2e332b74e31d##1; Hm_lpvt_f0984c42ef98965e03c60661581cd219=1560413345; SESSION=5ee4854d-34b7-423a-9cca-76ddc8a0f111; sid=5ee4854d-34b7-423a-9cca-76ddc8a0f111");
            };
            //            feignBuilder.Options.FeignClientPipeline.Service<ITestService>().Authorization(proxy =>
            //            {
            //#if NETSTANDARD
            //                return ("service", "asdasd");
            //#else
            //                return new AuthenticationHeaderValue("service", "asdasd");
            //#endif
            //            });
            feignBuilder.Options.FeignClientPipeline.SendingRequest += FeignClientPipeline_SendingRequest;
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").ReceivingResponse += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().ReceivingQueryResult();
            feignBuilder.Options.FeignClientPipeline.CancelRequest += (sender, e) =>
            {
                e.CancellationToken.Register((state) =>
                {
                }, sender);
            };
            feignBuilder.Options.FeignClientPipeline.ErrorRequest += (sender, e) =>
            {
                Exception exception = e.Exception;
                //e.ExceptionHandled = true;
            };
            return(feignBuilder);
        }
Beispiel #11
0
        public static IFeignBuilder AddTestFeignClients(this IFeignBuilder feignBuilder)
        {
            //feignBuilder.Options.IncludeMethodMetadata = true;
            feignBuilder.AddFeignClients(Assembly.GetExecutingAssembly(), FeignClientLifetime.Singleton);
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().SendingRequest += (sender, e) =>
            {
                //e.Terminate();
            };
            feignBuilder.Options.FeignClientPipeline.FallbackRequest += (sender, e) =>
            {
                var            parameters    = e.GetParameters();
                object         fallback      = e.Fallback;
                IFallbackProxy fallbackProxy = e.FallbackProxy;
                if (fallbackProxy == null)
                {
                    string s = "";
                }
                MethodInfo method = e.Method;
                e.Terminate();
            };
            feignBuilder.Options.FeignClientPipeline.Initializing += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").Initializing += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Disposing += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.Authorization(proxy =>
            {
#if NETSTANDARD
                return("global", "asdasd");
#else
                return(new AuthenticationHeaderValue("global", "asdasd"));
#endif
            });
            //feignBuilder.Options.FeignClientPipeline.BuildingRequest += FeignClientPipeline_BuildingRequest;
            feignBuilder.Options.FeignClientPipeline.Service <ITestService>().BuildingRequest += (sender, e) =>
            {
                IFeignClient <ITestService> feignClient = e.FeignClient as IFeignClient <ITestService>;
                ITestService service = feignClient.Service;
            };
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").BuildingRequest += (sender, e) =>
            {
                IFallbackFeignClient fallbackFeignClient = e.FeignClient.AsFallback();
                fallbackFeignClient = e.FeignClient.AsFallback <object>();
                fallbackFeignClient = e.FeignClient.AsFallback <ITestService>();

                var fallback = fallbackFeignClient?.Fallback;

                fallback = e.FeignClient.GetFallback();
                fallback = e.FeignClient.GetFallback <object>();
                fallback = e.FeignClient.GetFallback <ITestService>();

                if (!e.Headers.ContainsKey("Authorization"))
                {
                    e.Headers["Authorization"] = "service asdasd";
                }
                e.Headers["Accept-Encoding"] = "gzip, deflate, br";

                //add session
                e.Headers.Add("cookie", "csrftoken=EGxYkyZeT3DxEsvYsdR5ncmzpi9pmnQx; _bl_uid=nLjRstOyqOejLv2s0xtzqs74Xsmg; courseId=1; versionId=522; textbookId=2598; Hm_lvt_f0984c42ef98965e03c60661581cd219=1559783251,1559818390,1560213044,1560396804; uuid=6a30ff68-2b7c-4cde-a355-2e332b74e31d##1; Hm_lpvt_f0984c42ef98965e03c60661581cd219=1560413345; SESSION=5ee4854d-34b7-423a-9cca-76ddc8a0f111; sid=5ee4854d-34b7-423a-9cca-76ddc8a0f111");
            };
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").Authorization(proxy =>
            {
#if NETSTANDARD
                return("service", "asdasd");
#else
                return(new AuthenticationHeaderValue("service", "asdasd"));
#endif
            });
            feignBuilder.Options.FeignClientPipeline.SendingRequest += FeignClientPipeline_SendingRequest;
            feignBuilder.Options.FeignClientPipeline.Service("yun-platform-service-provider").ReceivingResponse += (sender, e) =>
            {
            };
            feignBuilder.Options.FeignClientPipeline.ReceivingQueryResult();
            feignBuilder.Options.FeignClientPipeline.CancelRequest += (sender, e) =>
            {
                e.CancellationToken.Register((state) =>
                {
                }, sender);
            };
            feignBuilder.Options.FeignClientPipeline.ErrorRequest += (sender, e) =>
            {
                Exception exception = e.Exception;
                //e.ExceptionHandled = true;
            };
            return(feignBuilder);
        }