コード例 #1
0
        private T GetInstance <T>()
        {
            _deployer.Deploy();
            var component = _manager.GetComponent(typeof(T));

            return((T)_manager.GetReference(component, _manager.CreateCreationalContext(component)));
        }
コード例 #2
0
        public InterceptorMethodHandler(WeldComponentManager manager, MethodInfo method, Interceptor[] interceptors, ICreationalContext creationalContext)
        {
            _interceptorReferences = new LinkedList <IAroundInvokeInterceptor>(
                interceptors.Select(x => manager.GetReference(x, creationalContext))
                .Cast <IAroundInvokeInterceptor>());

            _bindingsLazy = new Lazy <IEnumerable <IInterceptorBinding> >(() => method.GetAnnotations().OfType <IInterceptorBinding>().ToArray());

            var returnType = method.ReturnType;

            if (returnType == typeof(Task))
            {
                _isAsync    = true;
                _taskCaster = TaskCasters.ForVoid();
            }
            else if (returnType.IsGenericType)
            {
                var genericType = returnType.GetGenericTypeDefinition();
                if (genericType == typeof(Task <>))
                {
                    _isAsync    = true;
                    _taskCaster = TaskCasters.ForType(returnType.GetGenericArguments()[0]);
                }
            }
        }
コード例 #3
0
        public void FieldCircularDependencyShouldBeAllowed()
        {
            _deployer.AddTypes(typeof(One), typeof(Two));
            _deployer.Deploy();

            var component = _manager.GetComponent(typeof(One));
            var instance  = (One)_manager.GetReference(component, _manager.CreateCreationalContext(component));

            Assert.AreEqual(instance, instance.two.one);
        }