示例#1
0
 internal void SetDefault(Type type, string name, object instance)
 {
     if (!_container.IsRegistered(type, name))
     {
         _container.RegisterInstance(type, instance, name);
     }
 }
示例#2
0
        public static async Task AfterAll(IObjectContainer container)
        {
            Console.WriteLine("### AfterAll");

            if (container.IsRegistered <AutController>())
            {
                await container.Resolve <AutController>().StopAsync();
            }

            if (container.IsRegistered <WebDriverProvider>())
            {
                await container.Resolve <WebDriverProvider>().CleanUpAsync();
            }
        }
示例#3
0
        private ILogger GetLogger()
        {
            ILogger          logger          = null;
            IObjectContainer objectContainer = ObjectContainerFactory.GetObjectContainer();

            if (objectContainer.IsRegistered(typeof(ILogger), "STOPWATCH_LOGGER"))
            {
                return(objectContainer.Resolve <ILogger>("STOPWATCH_LOGGER"));
            }
            if (objectContainer.IsRegistered(typeof(ILogger)))
            {
                logger = objectContainer.Resolve <ILogger>();
            }
            return(logger);
        }
示例#4
0
 public void AfterScenario(IObjectContainer objectContainer)
 {
     if (objectContainer.IsRegistered <IScenarioDbContext>())
     {
         objectContainer.Resolve <IScenarioDbContext>().Cleanup();
     }
 }
 private static ICollection <IScenarioDependency> GetScenarioDependencies(IObjectContainer objectContainer)
 {
     if (!objectContainer.IsRegistered <ICollection <IScenarioDependency> >(ScenarioDependenciesName))
     {
         objectContainer.RegisterInstanceAs <ICollection <IScenarioDependency> >(new List <IScenarioDependency>(), ScenarioDependenciesName);
     }
     return(objectContainer.Resolve <ICollection <IScenarioDependency> >(ScenarioDependenciesName));
 }
示例#6
0
        public void RegisterToDiReolvedFromAutofac()
        {
            if (!scenarioContainer.IsRegistered <ISearchQueryService <JobProfileIndex> >())
            {
                scenarioContainer.RegisterInstanceAs(autofac.Resolve <ISearchQueryService <JobProfileIndex> >());
            }

            if (!scenarioContainer.IsRegistered <ISearchIndexConfig>())
            {
                scenarioContainer.RegisterInstanceAs(autofac.Resolve <ISearchIndexConfig>());
            }

            if (!scenarioContainer.IsRegistered <IMapper>())
            {
                scenarioContainer.RegisterInstanceAs(autofac.Resolve <IMapper>());
            }
        }
示例#7
0
 public object ResolveBindingInstance(Type bindingType, IObjectContainer scenarioContainer)
 {
     if (scenarioContainer.IsRegistered <IWindsorContainer>())
     {
         var componentContext = scenarioContainer.Resolve <IWindsorContainer>();
         return(componentContext.Resolve(bindingType));
     }
     return(scenarioContainer.Resolve(bindingType));
 }
示例#8
0
 public void Prepare(string name)
 {
     if (!container.IsRegistered <IWebDriver>(name))
     {
         var webdriver = SetupWebDriver();
         container.RegisterInstanceAs(webdriver, name: name);
         _name = name;
     }
 }
示例#9
0
        private OperationKey GetOperationKey(string value)
        {
            IObjectContainer objectContainer = ObjectContainerFactory.GetObjectContainer();

            if (!objectContainer.IsRegistered(typeof(IOperationKeyFormatter)))
            {
                objectContainer.RegisterType <IOperationKeyFormatter, OperationKeyFormatter>(new object[0]);
            }
            return(objectContainer.Resolve <IOperationKeyFormatter>().Parse(value));
        }
示例#10
0
        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            IObjectContainer objectContainer = ObjectContainerFactory.GetObjectContainer();

            if (objectContainer.IsRegistered(this.ContractType, this.Name))
            {
                return(objectContainer.Resolve(this.ContractType, this.Name));
            }
            return(Activator.CreateInstance(this.ServiceType));
        }
示例#11
0
        protected virtual IExecutionRule GetExecutionRule()
        {
            IObjectContainer objectContainer = ObjectContainerFactory.GetObjectContainer();

            if (!objectContainer.IsRegistered(typeof(IExecutionRule)))
            {
                objectContainer.RegisterType <IExecutionRule, NullExecutionRule>(new object[0]);
            }
            return(objectContainer.Resolve <IExecutionRule>());
        }
        public void InitializeWebDriver()
        {
            if (!objectContainer.IsRegistered <IWebDriver>())
            {
                RegisterWebDriver();
                return;
            }

            if (objectContainer.Resolve <IWebDriver>() == null)
            {
                RegisterWebDriver();
            }
        }
示例#13
0
        private void RegisterDbContext(IObjectContainer container)
        {
            IDbRuleContext instance = new DbRuleContext();

            container.RegisterInstance <IDbRuleContext>(instance);
            if (!container.IsRegistered(typeof(ISqlFormatter)))
            {
                container.RegisterType <ISqlFormatter, SqlServerFormatter>(new object[0]);
            }
            InjectionProperty property  = new InjectionProperty("DbObjectOperator", new ResolvedParameter <DbObjectOperator>());
            InjectionProperty property2 = new InjectionProperty("DbRuleContext", new ResolvedParameter <IDbRuleContext>());

            container.RegisterType <IDbContext, DbContext>(new object[] { property, property2 });
        }
示例#14
0
 private void TryLog(Exception ex)
 {
     try
     {
         IObjectContainer objectContainer = ObjectContainerFactory.GetObjectContainer();
         if (!objectContainer.IsRegistered(typeof(ILogger)))
         {
             objectContainer.RegisterType <ILogger, WcfLogger>(new object[0]);
         }
         objectContainer.Resolve <ILogger>().Error(ex, null);
     }
     catch (Exception exception)
     {
         Debug.WriteLine("WCF log exception error:");
         Debug.WriteLine(exception.Message);
     }
 }
示例#15
0
            internal void Register(IObjectContainer container)
            {
                if (container.IsRegistered(this.GetServiceType(), this.ContractName))
                {
                    return;
                }

                if (this.Instance != null)
                {
                    container.RegisterInstance(this.ContractType, this.Instance, this.ContractName);
                    return;
                }

                if (this.ContractType == null)
                {
                    container.RegisterType(this.TargetType, this.ContractName, this.Lifecycle);
                }
                else
                {
                    container.RegisterType(this.ContractType, this.TargetType, this.ContractName, this.Lifecycle);
                }
            }
示例#16
0
        private void RegisterUserAccessManager(IObjectContainer container)
        {
            bool flag   = string.Equals(ConfigurationManager.AppSettings["unique_login"], "true", StringComparison.OrdinalIgnoreCase);
            int  result = 0;

            if (!int.TryParse(ConfigurationManager.AppSettings["session_timeout"], out result))
            {
                result = -1;
            }
            if (result <= 0)
            {
                result = 0x493e0;
            }
            InjectionProperty property  = new InjectionProperty("EnableUniqueAccess", flag);
            InjectionProperty property2 = new InjectionProperty("Timeout", result);

            if (!container.IsRegistered(typeof(IPasswordEncryptor)))
            {
                container.RegisterType <IPasswordEncryptor, SimplePasswordEncryptor>(new object[0]);
            }
            InjectionConstructor constructor = new InjectionConstructor(new object[] { new ResolvedParameter <DbObjectOperator>(), new ResolvedParameter <IPasswordEncryptor>() });

            container.RegisterType <UserAccessManager, EGUserAccessManager>(new object[] { constructor, property, property2 });
        }
示例#17
0
 /// <summary>
 /// 返回一个 Boolean 值,表示是否给定的类型已经被服务定位器注册
 /// </summary>
 /// <typeparam name="T">检查的类型</typeparam>
 /// <returns>真表示已经被注册,否则为假.</returns>
 public bool IsRegistered <T>()
 {
     return(objectContainer.IsRegistered <T>());
 }
 /// <summary>
 /// 判断此类型是否已注册
 /// </summary>
 /// <typeparam name="T">注册类型</typeparam>
 /// <param name="that">容器</param>
 /// <param name="name">注册的名称</param>
 public static bool IsRegistered <T>(this IObjectContainer that, string name = null)
 {
     return(that.IsRegistered(typeof(T), name));
 }
示例#19
0
 /// <summary>
 /// 判断给定的类型是否已经注册
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public bool IsRegistered(Type type)
 {
     return(_container.IsRegistered(type));
 }
示例#20
0
            public object Invoke(object instance, object[] inputs, out object[] outputs)
            {
                object result = null;
                List <OperationAttribute> operationAttributes = null;
                int    num;
                object obj3;

                try
                {
                    OperationAttribute current;
                    operationAttributes = this.GetOperationAttributes();
                    using (List <OperationAttribute> .Enumerator enumerator = operationAttributes.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            current = enumerator.Current;
                            current.BeforeInvoke(instance, inputs);
                        }
                    }
                    result = this.invoker.Invoke(instance, inputs, out outputs);
                    if (operationAttributes.Count > 0)
                    {
                        for (num = operationAttributes.Count - 1; num >= 0; num--)
                        {
                            current = operationAttributes[num];
                            current.AfterInvoke(instance, inputs, result);
                        }
                    }
                    obj3 = result;
                }
                catch (Exception exception)
                {
                    this.TryLog(exception);
                    try
                    {
                        if ((operationAttributes != null) && (operationAttributes.Count > 0))
                        {
                            for (num = operationAttributes.Count - 1; num >= 0; num--)
                            {
                                operationAttributes[num].OnInvokeError(instance, inputs, result);
                            }
                        }
                    }
                    catch
                    {
                    }
                    IObjectContainer    objectContainer = ObjectContainerFactory.GetObjectContainer();
                    IExceptionFormatter formatter       = null;
                    if (objectContainer.IsRegistered(typeof(IExceptionFormatter)))
                    {
                        formatter = objectContainer.Resolve <IExceptionFormatter>();
                    }
                    if (formatter == null)
                    {
                        formatter = new ExceptionFormatter();
                        objectContainer.RegisterInstance <IExceptionFormatter>(formatter);
                    }
                    throw formatter.Format(exception);
                }
                finally
                {
                    try
                    {
                        WcfContext.Current.FindAll <DbObjectOperator>().ForEach(delegate(DbObjectOperator op)
                        {
                            try
                            {
                                op.DbOperator.Close();
                            }
                            catch
                            {
                            }
                        });
                    }
                    catch
                    {
                    }
                }
                return(obj3);
            }
示例#21
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            string           name            = serviceHostBase.Description.Name;
            Type             serviceType     = serviceHostBase.Description.ServiceType;
            IObjectContainer objectContainer = ObjectContainerFactory.GetObjectContainer();

            foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
            {
                foreach (EndpointDispatcher dispatcher2 in dispatcher.Endpoints)
                {
                    foreach (ServiceEndpoint endpoint in serviceHostBase.Description.Endpoints)
                    {
                        Type contractType = endpoint.Contract.ContractType;
                        if (((endpoint.Contract.Name == dispatcher2.ContractName) && (endpoint.Contract.Namespace == dispatcher2.ContractNamespace)) && (endpoint.Contract.ContractType != null))
                        {
                            if (serviceType.GetInterfaces().Any <Type>(t => (t == contractType)) && !objectContainer.IsRegistered(contractType))
                            {
                                objectContainer.RegisterType(contractType, serviceType, name, new object[0]);
                            }
                            dispatcher2.DispatchRuntime.InstanceProvider = new EGInstanceProvider(contractType, serviceType, name);
                            lock (this)
                            {
                                foreach (OperationDescription description in endpoint.Contract.Operations)
                                {
                                    if ((description.Behaviors != null) && ((from t in description.Behaviors
                                                                             where t.GetType() == typeof(EGOperationBehavior)
                                                                             select t).Count <IOperationBehavior>() <= 0))
                                    {
                                        IOperationBehavior item = new EGOperationBehavior();
                                        description.Behaviors.Add(item);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }