public void RegisterComponent()
        {
            IComponentAdapter componentAdapter =
                CreateComponentAdapterFactory().CreateComponentAdapter(typeof(ITouchable), typeof(SimpleTouchable),
                                                                       null);

            picoContainer.RegisterComponent(componentAdapter);

            Assert.IsTrue(picoContainer.ComponentAdapters.Contains(componentAdapter));
        }
Exemplo n.º 2
0
        protected virtual IPicoContainer WrapComponentInstances(Type decoratingComponentAdapterClass,
                                                                IPicoContainer picoContainer,
                                                                object[] wrapperDependencies)
        {
            Assert.IsTrue(typeof(DecoratingComponentAdapter).IsAssignableFrom(decoratingComponentAdapterClass));
            IMutablePicoContainer mutablePicoContainer = new DefaultPicoContainer();
            int         size = (wrapperDependencies != null ? wrapperDependencies.Length : 0) + 1;
            ICollection allComponentAdapters = picoContainer.ComponentAdapters;

            foreach (object adapter in allComponentAdapters)
            {
                IParameter[] parameters = new IParameter[size];
                parameters[0] = new ConstantParameter(adapter);
                for (int i = 1; i < parameters.Length; i++)
                {
                    parameters[i] = new ConstantParameter(wrapperDependencies[i - 1]);
                }
                IMutablePicoContainer instantiatingPicoContainer =
                    new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory());
                instantiatingPicoContainer.RegisterComponentImplementation("decorator", decoratingComponentAdapterClass,
                                                                           parameters);
                mutablePicoContainer.RegisterComponent(
                    (IComponentAdapter)instantiatingPicoContainer.GetComponentInstance("decorator"));
            }
            return(mutablePicoContainer);
        }