Example #1
0
        /// <summary>
        ///   Registers this component with the <see cref = "IKernel" />.
        /// </summary>
        /// <param name = "kernel">The kernel.</param>
        void IRegistration.Register(IKernelInternal kernel)
        {
            if (registered)
            {
                return;
            }
            registered = true;
            var services = FilterServices(kernel);

            if (services.Length == 0)
            {
                return;
            }

            var componentModel = kernel.ComponentModelBuilder.BuildModel(GetContributors(services));

            if (SkipRegistration(kernel, componentModel))
            {
                return;
            }
            kernel.AddCustomComponent(componentModel);
        }
Example #2
0
        private IHandler BuildHandlerGeneric <T>()
        {
            var model = kernel.ComponentModelBuilder.BuildModel(
                new ComponentName("castle.auto-collection: " + typeof(T).ToCSharpString(), false),
                new[]
            {
                typeof(IEnumerable <T>),
                typeof(ICollection <T>),
                typeof(IList <T>),
                typeof(T[])
            },
                typeof(T[]),
                null);

            if (model.LifestyleType == LifestyleType.Undefined)
            {
                model.LifestyleType = LifestyleType.Transient;
            }
            if (model.CustomLifestyle == null)
            {
                model.CustomComponentActivator = typeof(CollectionActivator <T>);
            }
            return(kernel.AddCustomComponent(model, isMetaHandler: true));
        }
Example #3
0
        /// <summary>
        ///   Performs the registration in the <see cref="T:Castle.MicroKernel.IKernel" />.
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        public virtual void Register(IKernelInternal kernel)
        {
            if (m_registered)
            {
                return;
            }

            // create component configuration with resolved properties
            CreateDependencyDescripters(kernel);

            // setup lifestyle
            if (!IsLifestyleOverridenWithDescriptor)
            {
                AddDescriptor(new LifestyleDescriptor <TService>(m_lifestyle));
            }

            IComponentModelDescriptor[] contributors = GetContributors();

            ComponentModel componentModel = kernel.ComponentModelBuilder.BuildModel(contributors);

            kernel.AddCustomComponent(componentModel);

            m_registered = true;
        }