Example #1
0
        /// <summary>
        /// Usually the implementation will look in the configuration property
        /// of the model or the service interface, or the implementation looking for
        /// something.
        /// </summary>
        /// <param name="kernel">The kernel instance</param>
        /// <param name="model">The component model</param>
        public void ProcessModel(IKernel kernel, ComponentModel model)
        {
            if (model.Configuration != null &&
                model.Configuration.Attributes[SCOPE_TOKEN]!=null)
            {
                ScopeAttribute scopeAttribute = new ScopeAttribute();
                scopeAttribute.Scope = model.Configuration.Attributes[SCOPE_TOKEN];
                
                if (model.Configuration.Attributes[SCOPE_TOKEN]!=null)
                {
                    bool result = false;
                    bool.TryParse(model.Configuration.Attributes[PROXY_TOKEN], out result);
                    if (result)
                    {
                        scopeAttribute.UseProxy = bool.Parse(model.Configuration.Attributes[PROXY_TOKEN]);
                    }
                }

                DecorateComponent(model, scopeAttribute);
            }
            else if (AttributeUtil.HasScopeAttribute(model.Implementation))
            {
                ScopeAttribute scopeAttribute = AttributeUtil.GetScopeAttribute(model.Implementation);
                DecorateComponent(model, scopeAttribute);
            }                
        }
Example #2
0
        /// <summary>
        /// Decorates the component.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="scopeAttribute">The scope attribute.</param>
        private void DecorateComponent(ComponentModel model, ScopeAttribute scopeAttribute)
        {
           if (!model.Name.StartsWith(ProxyScopeInterceptor.TARGET_NAME_PREFIX))
            {
                if (scopeAttribute.UseProxy)
                {
                    scopeAttribute.Scope = ScopeType.Singleton;
                    
                    model.CustomComponentActivator = typeof (ScopeComponentActivator);

                    // Ensure its CustomLifestyle
                    model.LifestyleType = LifestyleType.Custom;
                    model.CustomLifestyle = typeof(ScopeLifestyleManager);
                }
                else
                {
                    // Ensure its CustomLifestyle
                    model.LifestyleType = LifestyleType.Custom;
                    model.CustomLifestyle = typeof (ScopeLifestyleManager);

                    // Add the bijection interceptor
                    if (NeedBijection(model))
                    {
                        model.Interceptors.AddFirst(new InterceptorReference(typeof (BijectionInterceptor)));
                    }
                }
                model.ExtendedProperties.Add(SCOPE_ATTRIBUTE, scopeAttribute);
            }
            else
            {
                model.ExtendedProperties.Add(SCOPE_ATTRIBUTE, scopeAttribute);
                // Ensure its CustomLifestyle
                model.LifestyleType = LifestyleType.Custom;
                model.CustomLifestyle = typeof(ScopeLifestyleManager);

                // Add the bijection interceptor
                if (NeedBijection(model))
                {
                    model.Interceptors.AddFirst(new InterceptorReference(typeof(BijectionInterceptor)));
                }
            }
        }