예제 #1
0
        public virtual void RegisterCommand(ICommand command, String parameterBean, int priority)
        {
            if (String.IsNullOrEmpty(parameterBean))
            {
                throw new Exception("Empty beanname is not allowed. Use ICommandStringParameterExtendable instead.");
            }
            Object parameter = BeanContext.GetService(parameterBean);

            RegisterCommandIntern(command, parameter, priority, parameterBean);
        }
예제 #2
0
        public SyncInterface GetService <AsyncInterface, SyncInterface>(params ISecurityScope[] securityScopes)
            where AsyncInterface : class, ICommunicationObject
            where SyncInterface : class
        {
            AsyncInterface service = BeanContext.GetService <IServiceFactory>().GetService <AsyncInterface>(securityScopes);

            SyncCallInterceptor synchronizedInterceptor = BeanContext.RegisterBean <SyncCallInterceptor>().PropertyValue("AsyncService", service).PropertyValue("AsyncServiceInterface", typeof(AsyncInterface)).Finish();

            return((SyncInterface)ProxyFactory.CreateProxy(typeof(SyncInterface), synchronizedInterceptor));
        }
예제 #3
0
        public void testAutowired()
        {
            InitManually(GetType());
            Bean1 bean1 = BeanContext.GetService <Bean1>(bean1Name);

            Assert.AssertNull(bean1.bean2);
            Assert.AssertNotNull(bean1.bean2Autowired);
            Assert.AssertNull(bean1.bean3);
            Assert.AssertNull(bean1.bean3Autowired);
        }
예제 #4
0
        public void TestExtensionPointByType()
        {
            InitManually(GetType());
            ITestListenerExtendable2 testListenerExtendable = BeanContext.GetService <ITestListenerExtendable2>("testExtensionPoint2");
            ITestListenerRegistry2   testListenerRegistry   = BeanContext.GetService <ITestListenerRegistry2>("testExtensionPoint2");

            testListenerExtendable.RegisterTestListener(new DummyListener(), typeof(IList));

            ITestListener testListener = testListenerRegistry.GetTestListener(typeof(ArrayList));

            Assert.IsNotNull(testListener);
        }
예제 #5
0
        public void TestExtensionPoint()
        {
            InitManually(GetType());
            ITestListenerExtendable testListenerExtendable = BeanContext.GetService <ITestListenerExtendable>("testExtensionPoint");
            ITestListenerRegistry   testListenerRegistry   = BeanContext.GetService <ITestListenerRegistry>("testExtensionPoint");

            testListenerExtendable.AddTestListener(new DummyListener());

            ITestListener[] testListeners = testListenerRegistry.GetTestListeners();
            Assert.IsNotNull(testListeners);
            Assert.AreEqual(1, testListeners.Length);
        }
예제 #6
0
        public void autowiredVisibility()
        {
            AutowiredTestBean bean = BeanContext.GetService <AutowiredTestBean>();

            Assert.AssertSame(BeanContext, bean.getBeanContextPrivate());
            Assert.AssertNull(bean.getBeanContextPrivateSetter());
            Assert.AssertSame(BeanContext, bean.getBeanContextPrivateSetterAutowired());

            Assert.AssertSame(BeanContext, bean.getBeanContextProtected());
            Assert.AssertNull(bean.getBeanContextProtectedSetter());
            Assert.AssertSame(BeanContext, bean.getBeanContextProtectedSetterAutowired());

            Assert.AssertSame(BeanContext, bean.getBeanContextPublic());
            Assert.AssertSame(BeanContext, bean.getBeanContextPublicSetter());
        }
예제 #7
0
        protected Object ResolveListener()
        {
            Object listener = this.Listener;

            if (listener != null)
            {
                listener      = ResolveListenerIntern(listener);
                this.Listener = listener;
                return(listener);
            }
            else if (ListenerBeanName != null)
            {
                listener = BeanContext.GetService(ListenerBeanName, !Optional);
                if (listener == null)
                {
                    return(null);
                }
            }
            else if (ListenerBean != null)
            {
                ListenerBeanName = ListenerBean.GetName();
                if (ListenerBeanName == null)
                {
                    listener = ListenerBean.GetInstance();
                    if (listener == null)
                    {
                        throw new LinkException("No listener instance received from " + ListenerBean.GetType().FullName + ".getInstance()" + " to link to registry", this);
                    }
                }
                else
                {
                    listener = BeanContext.GetService(ListenerBeanName, !Optional);
                    if (listener == null)
                    {
                        return(null);
                    }
                }
            }
            else
            {
                throw new LinkException("Listener not found. Must never happen.", this);
            }
            listener      = ResolveListenerIntern(listener);
            this.Listener = listener;
            return(listener);
        }
예제 #8
0
 protected Object[] GetConstructorArguments(ConstructorInfo constructor)
 {
     ParameterInfo[] parameterTypes = constructor.GetParameters();
     Object[]        beanArgs       = new Object[parameterTypes.Length];
     for (int a = parameterTypes.Length; a-- > 0;)
     {
         Type parameterType = parameterTypes[a].ParameterType;
         if (typeof(IEntityFactory).Equals(parameterType))
         {
             beanArgs[a] = Self;
         }
         else
         {
             beanArgs[a] = BeanContext.GetService(parameterType);
         }
     }
     return(beanArgs);
 }
예제 #9
0
        protected Object resolveListener()
        {
            Object listener = Listener;

            Object listenerTarget;

            if (listener != null && !(listener is LateDelegate))
            {
                listenerTarget = listener;
            }
            else if (ListenerBeanName != null)
            {
                listenerTarget = BeanContext.GetService(ListenerBeanName);
            }
            else if (ListenerBean != null)
            {
                ListenerBeanName = ListenerBean.GetName();
                if (ListenerBeanName == null)
                {
                    listenerTarget = ListenerBean.GetInstance();
                    if (listenerTarget == null)
                    {
                        throw new System.Exception("No listener instance received from " + ListenerBean.GetType().FullName + ".getInstance()" + " to link to registry");
                    }
                }
                else
                {
                    listenerTarget = BeanContext.GetService(ListenerBeanName);
                }
            }
            else
            {
                throw new System.Exception("Listener not found. Must never happen.");
            }
            if (listener is LateDelegate)
            {
                listener = ((LateDelegate)listener).GetDelegate(listener.GetType(), listenerTarget);
            }
            else
            {
                listener = listenerTarget;
            }
            return(resolveListenerIntern(listener));
        }
예제 #10
0
        protected Object resolveRegistry()
        {
            Object registry;

            if (RegistryBeanName != null)
            {
                registry = BeanContext.GetService(RegistryBeanName);
                if (registry == null)
                {
                    throw new System.Exception("No registry bean with name '" + RegistryBeanName + "' found to link bean");
                }
                return(registry);
            }
            registry = BeanContext.GetService(RegistryBeanAutowiredType);
            if (registry == null)
            {
                throw new System.Exception("No registry bean with autowired type " + RegistryBeanAutowiredType.FullName + " found to link bean");
            }
            return(registry);
        }
예제 #11
0
        protected Object ResolveRegistry()
        {
            Object registry = this.Registry;

            if (registry != null)
            {
                registry = ResolveRegistryIntern(registry);
                return(registry);
            }
            if (RegistryBeanName != null)
            {
                registry = BeanContext.GetService(RegistryBeanName, !Optional);
            }
            else
            {
                registry = BeanContext.GetService(RegistryBeanAutowiredType, !Optional);
            }
            registry      = ResolveRegistryIntern(registry);
            this.Registry = registry;
            return(registry);
        }
예제 #12
0
 public virtual Object this[String xamlBeanName]
 {
     get
     {
         if (CurrentBeanContext != null)
         {
             Object ret = CurrentBeanContext.GetService(xamlBeanName, false);
             if (ret != null)
             {
                 return(ret);
             }
         }
         if (BeanContext != null && BeanContext.IsRunning)
         {
             if (!IsLazyBindingAllowed)
             {
                 Debug.WriteLine("Forced Binding: " + xamlBeanName);
             }
             return(BeanContext.GetService(xamlBeanName));
         }
         if (BeanContext != null && BeanContext.IsDisposed)
         {
             Debug.WriteLine("Binding after Dispose of BeanContext: " + xamlBeanName);
             return(null);
         }
         if (!IsLazyBindingAllowed)
         {
             throw new Exception("Lazy Binding is not allowed.");
         }
         return(CreateEvaluateLaterBinding(xamlBeanName));
     }
     set
     {
         throw new Exception("It is not allowed to set a value which contains only a beanName without a property: '" + xamlBeanName + "'");
     }
 }