예제 #1
0
 public UserService(ICAPPublisher publisher, IServiceFinder <ConsulService> serviceFinder, ILoadBalancer loadBalancer, IConfiguration configuration)
 {
     _publisher     = publisher;
     _loadBalancer  = loadBalancer;
     _serviceFinder = serviceFinder;
     _conf          = configuration;
 }
예제 #2
0
 public SubscribeService(IServiceFinder <ConsulService> serviceFinder, ILoadBalancer loadBalancer, ITopicService topicService, IConfiguration conf)
 {
     _serviceFinder = serviceFinder;
     _loadBalancer  = loadBalancer;
     _topicServce   = topicService;
     _conf          = conf;
 }
예제 #3
0
 public GrpcProxyFactory(IResolver resolver, IProxyProvider proxyProvider, AsyncProxyGenerator proxyGenerator,
                         IServiceFinder finder) :
     base(resolver, proxyProvider, proxyGenerator)
 {
     _finder = finder;
     //GRpc Http支持
     AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
 }
 public CustomTokenRefreshService(IServiceFinder <ConsulService> serviceFinder, ILoadBalancer loadBalancer, IRedisCache cache, OcelotConfiguration options, IConfiguration configuration)
 {
     _serviceFinder = serviceFinder;
     _loadBalancer  = loadBalancer ?? new WeightRoundBalancer();
     _options       = options;
     _cache         = cache;
     _conf          = configuration;
 }
예제 #5
0
 public Converter(ILogger <Converter> logger,
                  IConfiguration configuration,
                  IServiceFinder <IReader> readerFinder,
                  IServiceFinder <IWriter> writerFinder)
 {
     _logger        = logger;
     _configuration = configuration;
     _readerFinder  = readerFinder;
     _writerFinder  = writerFinder;
 }
예제 #6
0
        /// <summary>
        /// Configure service finder of the service host.
        /// </summary>
        /// <param name="configure">
        /// The configure action.
        /// </param>
        /// <returns>
        /// The configured service host.
        /// </returns>
        public ServiceHost ServiceFinder(Action <ServiceFinderConfiguration> configure)
        {
            var configuration = new ServiceFinderConfiguration();

            configure(configuration);

            _serviceFinder = configuration.ServiceFinder;

            return(this);
        }
예제 #7
0
        /// <summary>
        /// Set the default values unless they are already set.
        /// </summary>
        private void SetDefaultValues()
        {
            if (_containerAdapter == null)
            {
                throw new InvalidOperationException(@"Cannot start with a null container adapter!");
            }

            if (_serviceFinder == null)
            {
                _serviceFinder = new NullServiceFinder();
            }
        }
예제 #8
0
        public ReadOnlyContainer(IStorage storage, IServiceFinder serviceFinder, ITypeGetter typeGetter, IServiceInstanceResolver serviceInstanceResolver,
                                 IAssemblyRegistrar assemblyRegistrar, IServiceRegistrar serviceRegistrar, IServicesGenerator servicesGenerator)
        {
            ServiceFinder           = serviceFinder;
            TypeGetter              = typeGetter;
            ServiceInstanceResolver = serviceInstanceResolver;
            AssemblyRegistrar       = assemblyRegistrar;
            ServiceRegistrar        = serviceRegistrar;
            ServicesGenerator       = servicesGenerator;

            Storage = storage;
        }
예제 #9
0
 public Container(IStorage storage, IServiceRegistrar serviceRegistrar, IServicesGenerator servicesGenerator, IServiceFinder serviceFinder,
                  IServiceInitializer serviceInitializer, ITypeExisterChecker typeExisterChecker, IServiceIsAutoValueChecker serviceIsAutoValueChecker,
                  ITypeGetter typeGetter, IAssemblyRegistrar assemblyRegistrar, IConstructorParametersByObjectsGenerator constructorParametersByObjectsGenerator,
                  IServiceInstanceResolver serviceInstanceResolver) : base(storage, serviceFinder, typeGetter, serviceInstanceResolver, assemblyRegistrar, serviceRegistrar, servicesGenerator)
 {
     ServicesGenerator         = servicesGenerator;
     ServiceFinder             = serviceFinder;
     ServiceInitializer        = serviceInitializer;
     ServiceIsAutoValueChecker = serviceIsAutoValueChecker;
     ConstructorParametersByObjectsGenerator = constructorParametersByObjectsGenerator;
     TypeGetter              = typeGetter;
     AssemblyRegistrar       = assemblyRegistrar;
     ServiceInstanceResolver = serviceInstanceResolver;
 }
예제 #10
0
        public static async Task <T> PostAsync <T, S>(
            this HttpClient httpClient,
            string serviceName,
            string virtualPath,
            string code = null,
            object body = null,
            IServiceFinder <S> serviceFinder = null,
            ILoadBalancer balancer           = null) where S : IService
        {
            if (serviceName.IsNullOrEmpty())
            {
                throw new AngleExceptions("service name not exits");
            }

            if (virtualPath.IsNullOrEmpty())
            {
                throw new AngleExceptions("virtualPath not exits");
            }

            if (serviceFinder.IsNull())
            {
                throw new AngleExceptions("serviceFinder cannot be null");
            }

            balancer = balancer ?? new WeightRoundBalancer();

            var userServices = await serviceFinder.FindByNameAsync(serviceName);

            var foundedService = default(S);

            if (!userServices.IsNull() && userServices.Count > 0)
            {
                var servicesDictionary = (from us in userServices select new { service = us, weight = us.Weight, }).ToDictionary(x => x.service, y => y.weight);
                foundedService = balancer.Balance(servicesDictionary);
            }

            using (var client = new HttpClient())
            {
                var url = foundedService?.Address.ToString() + virtualPath;

                if (!code.IsNullOrEmpty())
                {
                    client.DefaultRequestHeaders.Add("Authorization", code);
                }

                return(await client.PostAsync <T>(url, body));
            }
        }
예제 #11
0
        // This method is generates a class during runtime that implements a interface given in Type argument
        public static T GenerateClass <T>(IServiceFinder serviceFinder, HttpClient http, Type[] inheritedTypes = null)
        {
            try
            {
                var t = typeof(T);

                if (!t.IsInterface)
                {
                    throw new ProxyException("Only interface types are allowed");
                }

                var typeBuilder = CreateTypeBuilder(); // Creates a class type

                var methods = t.GetMethods().ToList();
                if (inheritedTypes != null)
                {
                    foreach (Type type in inheritedTypes)
                    {
                        methods.AddRange(type.GetMethods());
                    }
                }

                // Add a field to the class
                var field = CreateFiled(typeBuilder);
                // Add a constructor to the class
                CreateCotr(typeBuilder, field);

                var serviceUri = serviceFinder.GetServiceUri(typeof(T));

                foreach (var m in methods)
                {
                    // Create and add a method implementation for each method in the interface to the class
                    CreateMethod(m, typeBuilder, field, serviceUri);
                }

                typeBuilder.AddInterfaceImplementation(t);                                                   // Add interface implementation to the class

                return((T)Activator.CreateInstance(typeBuilder.CreateTypeInfo().AsType(), new Proxy(http))); // Create class type and instantiate it
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #12
0
 public void Start(ServiceConfig serviceConfig)
 {
     IServiceAssembliesResolver assembliesResolver = GlobalSetting.Container.GetService<IServiceAssembliesResolver>();
     if (assembliesResolver == null)
         throw new NullReferenceException("IServiceAssembliesResolver接口不能为空");
     IServiceFinder serviceFinder = GlobalSetting.Container.GetService<IServiceFinder>();
     if (serviceFinder == null)
         throw new NullReferenceException("IServiceFinder接口不能为空");
     IEnumerable<ServiceMap> serviceMaps = FilterServiceMap(serviceFinder.Find(assembliesResolver.GetAssemblies()), serviceConfig.Server.Services);
     IServiceDiscoverer serviceDiscoverer = GlobalSetting.Container.GetService<IServiceDiscoverer>();
     if (serviceDiscoverer == null)
         throw new NullReferenceException("IServiceDiscoverer接口不能为空");
     serviceDiscoverer.RegistrationCenter = serviceConfig.RegistrationCenter;
     IEnumerable<Service> servics = FilterServices(serviceDiscoverer.Discover(serviceMaps), serviceConfig.Client.Services);
     IThriftClientActivator thriftClientActivator = GlobalSetting.Container.GetService<IThriftClientActivator>();
     if (thriftClientActivator == null)
         throw new NullReferenceException("IThriftClientActivator接口不能为空");
     thriftClientActivator.RegisterServices(servics);
 }
 public CustomAuthenticateService(IServiceFinder <ConsulService> serviceFinder, IConfiguration configuration)
 {
     _serviceFinder = serviceFinder;
     _configuration = configuration;
 }
예제 #14
0
 public GRPCConsulServiceFinder(IServiceFinder <ConsulService> serviceFinder)
 {
     _serviceFinder = serviceFinder;
 }
예제 #15
0
파일: ClientProxy.cs 프로젝트: lulzzz/spear
 /// <inheritdoc />
 /// <summary> 构造函数 </summary>
 public ClientProxy()
 {
     _logger        = LogManager.Logger <ClientProxy>();
     _clientFactory = ClientContext.Resolve <IMicroClientFactory>();
     _serviceFinder = ClientContext.Resolve <IServiceFinder>();
 }
 /// <summary>
 /// Use the specified service finder.
 /// </summary>
 /// <param name="serviceFinder">
 /// The service finder.
 /// </param>
 public void Use(IServiceFinder serviceFinder)
 {
     ServiceFinder = serviceFinder;
 }
예제 #17
0
 public ServiceInvoker(IApiFinder apiFinder, IServiceFinder serviceFinder, IHttpInvoker httpInvoker)
 {
     _apiFinder     = apiFinder;
     _serviceFinder = serviceFinder;
     _httpInvoker   = httpInvoker;
 }
예제 #18
0
 /// <inheritdoc />
 /// <summary> 构造函数 </summary>
 public ClientProxy(ILogger <ClientProxy> logger, IServiceProvider provider, IServiceFinder finder)
 {
     _logger        = logger;
     _provider      = provider;
     _serviceFinder = finder;
 }
예제 #19
0
 public TypeExisterChecker(IServiceFinder finder)
 {
     Finder = finder;
 }