// <inheritdoc/>
        public async Task AddVertices <T>(List <T> listOfObjects, string label, string partitionKey, string filterName)
        {
            var databaseOperator = serviceResolver.ResolveService <IDatabaseOperator>().Initialize(server);

            foreach (var obj in listOfObjects)
            {
                databaseOperator.AddUpsertVerticeQuery(obj, partitionKey, label, GetVerticeFilter(obj, filterName));
            }

            await clockService.ExecuteWithStopWatchAsync("Executing AddVertices batch operations on database", async() => {
                await databaseOperator.ExecuteOperations();
            });
        }
Ejemplo n.º 2
0
 public void InjectServicesTo(object target)
 {
     this.target = target;
     foreach (var field in ServiceFields)
     {
         var service = resolver.ResolveService(field.FieldType);
         field.SetValue(target, service);
     }
 }
Ejemplo n.º 3
0
        public T CreateService()
        {
            var constructor    = implementationType.GetConstructors()[0];
            var parametersInfo = constructor.GetParameters();
            var parameters     = new object[parametersInfo.Length];

            for (int i = 0; i < parametersInfo.Length; i++)
            {
                var settings = resolver.ResolveService(parametersInfo[i].ParameterType);
                parameters[i] = settings;
            }
            var newService = constructor.Invoke(parameters);

            return((T)newService);
        }
Ejemplo n.º 4
0
 public object GetService(Type type)
 {
     return(resolver.ResolveService(type));
 }
 public virtual object ResolveService(Type type)
 {
     return(wrappee.ResolveService(type));
 }
Ejemplo n.º 6
0
 public T ResolveService <T>() where T : class
 {
     return(_serviceBuilderResolver.ResolveOptionalService <T>() ??
            _serviceResolver.ResolveService <T>());
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取本地服务
        /// </summary>
        /// <typeparam name="IServiceInterfaceType"></typeparam>
        /// <returns></returns>
        private IServiceInterfaceType GetLocalService <IServiceInterfaceType>()
        {
            Type serviceType = typeof(IServiceInterfaceType);

            //定义异常
            Exception ex = new ArgumentException("Generic parameter type - 【" + serviceType.FullName
                                                 + "】 must be an interface marked with ServiceContractAttribute.");

            if (!serviceType.IsInterface)
            {
                throw ex;
            }
            else
            {
                bool markedWithServiceContract = false;
                var  attr = CoreHelper.GetTypeAttribute <ServiceContractAttribute>(serviceType);
                if (attr != null)
                {
                    markedWithServiceContract = true;
                }

                if (!markedWithServiceContract)
                {
                    throw ex;
                }
            }

            //定义本地服务
            IServiceInterfaceType ls = default(IServiceInterfaceType);

            //如果是本地配置,则抛出异常
            if (config.Type != CastleFactoryType.Remote)
            {
                if (resolver != null)
                {
                    ls = resolver.ResolveService <IServiceInterfaceType>(container);
                }

                if (ls == null)
                {
                    var serviceKey = "Service_" + serviceType.FullName;

                    //本地服务
                    if (container.Kernel.HasComponent(serviceKey))
                    {
                        lock (hashtable.SyncRoot)
                        {
                            if (!hashtable.ContainsKey(serviceType))
                            {
                                //返回本地服务
                                var service      = container.Resolve <IService>(serviceKey);
                                var handler      = new LocalInvocationHandler(config, container, service, serviceType, cache, logger);
                                var dynamicProxy = ProxyFactory.GetInstance().Create(handler, serviceType, true);

                                hashtable[serviceType] = dynamicProxy;
                            }
                        }

                        ls = (IServiceInterfaceType)hashtable[serviceType];
                    }
                }

                if (ls == null)
                {
                    if (config.Type == CastleFactoryType.Local)
                    {
                        throw new WarningException(string.Format("The local【{1}({2})】not find matching service ({0})."
                                                                 , serviceType.FullName, DnsHelper.GetHostName(), DnsHelper.GetIPAddress()));
                    }
                }
            }

            return(ls);
        }