Example #1
0
        private ILifestyleManager CreateProxyLifestyleManager(IComponentInfo info, ILifestyleManager lifestyleMgr)
        {
            if (info.ExtendedProperties.ContainsKey("proxy"))
            {
                lifestyleMgr = new ProxyLifestyleManager(lifestyleMgr);
            }

            return(lifestyleMgr);
        }
Example #2
0
		/// <summary>
		/// Saves the kernel instance, subscribes to 
		/// <see cref="IKernelEvents.AddedAsChildKernel"/> event,
		/// creates the lifestyle manager instance and computes
		/// the handler state.
		/// </summary>
		/// <param name="kernel"></param>
		public virtual void Init(IKernel kernel)
		{
			this.kernel = kernel;
			this.kernel.AddedAsChildKernel += new EventHandler(OnAddedAsChildKernel);

			IComponentActivator activator = kernel.CreateComponentActivator(ComponentModel);

			lifestyleManager = CreateLifestyleManager(activator);

			EnsureDependenciesCanBeSatisfied();
		}
        public virtual void Init(IKernel kernel)
        {
            this.kernel = kernel;
            this.kernel.AddedAsChildKernel += new EventHandler(OnAddedAsChildKernel);

            IComponentActivator activator = kernel.CreateComponentActivator(ComponentModel);

            lifestyleManager = CreateLifestyleManager(activator);

            EnsureDependenciesCanBeSatisfied();
        }
Example #4
0
 public ComponentRegistration(IComponentInfo info, ILifestyleManager lifestyleManager)
 {
     Component        = info;
     LifestyleManager = lifestyleManager;
     if (!info.IsGenericType())
     {
         ComponentContext = new ComponentContext(lifestyleManager.Kernel, null)
         {
             LifestyleManager = lifestyleManager, Component = info
         };
     }
 }
		protected override void InitDependencies()
		{
			var activator = Kernel.CreateComponentActivator(ComponentModel);
			lifestyleManager = Kernel.CreateLifestyleManager(ComponentModel, activator);

			var awareActivator = activator as IDependencyAwareActivator;
			if (awareActivator != null && awareActivator.CanProvideRequiredDependencies(ComponentModel))
			{
				return;
			}

			base.InitDependencies();
		}
        protected override void InitDependencies()
        {
            var activator = Kernel.CreateComponentActivator(ComponentModel);

            lifestyleManager = Kernel.CreateLifestyleManager(ComponentModel, activator);

            var awareActivator = activator as IDependencyAwareActivator;

            if (awareActivator != null && awareActivator.CanProvideRequiredDependencies(ComponentModel))
            {
                return;
            }

            base.InitDependencies();
        }
        protected virtual ILifestyleManager CreateLifestyleManager(IComponentActivator activator)
        {
            ILifestyleManager manager = null;

            if (ComponentModel.LifestyleType == LifestyleType.Undefined ||
                ComponentModel.LifestyleType == LifestyleType.Singleton)
            {
                manager = new Lifestyle.SingletonLifestyleManager();
            }
            else if (ComponentModel.LifestyleType == LifestyleType.Thread)
            {
                manager = new Lifestyle.PerThreadLifestyleManager();
            }
            else if (ComponentModel.LifestyleType == LifestyleType.Transient)
            {
                manager = new Lifestyle.TransientLifestyleManager();
            }
            else if (ComponentModel.LifestyleType == LifestyleType.Custom)
            {
                manager = (ILifestyleManager)
                          Activator.CreateInstance(ComponentModel.CustomLifestyle);
            }
            else if (ComponentModel.LifestyleType == LifestyleType.Pooled)
            {
                int initial = ExtendedPropertiesConstants.Pool_Default_InitialPoolSize;
                int maxSize = ExtendedPropertiesConstants.Pool_Default_MaxPoolSize;

                if (ComponentModel.ExtendedProperties.Contains(ExtendedPropertiesConstants.Pool_InitialPoolSize))
                {
                    initial = (int)ComponentModel.ExtendedProperties[ExtendedPropertiesConstants.Pool_InitialPoolSize];
                }
                if (ComponentModel.ExtendedProperties.Contains(ExtendedPropertiesConstants.Pool_MaxPoolSize))
                {
                    maxSize = (int)ComponentModel.ExtendedProperties[ExtendedPropertiesConstants.Pool_MaxPoolSize];
                }

                manager = new Lifestyle.PoolableLifestyleManager(initial, maxSize);
            }

            manager.Init(activator, Kernel);

            return(manager);
        }
Example #8
0
        /// <summary>
        ///   Saves the kernel instance, subscribes to
        ///   <see cref = "IKernelEvents.AddedAsChildKernel" />
        ///   event,
        ///   creates the lifestyle manager instance and computes
        ///   the handler state.
        /// </summary>
        /// <param name = "kernel"></param>
        public virtual void Init(IKernelInternal kernel)
        {
            if (kernel == null)
            {
                throw new ArgumentNullException("kernel");
            }
            this.kernel = kernel;
            this.kernel.AddedAsChildKernel += OnAddedAsChildKernel;

            var activator = this.kernel.CreateComponentActivator(ComponentModel);

            lifestyleManager = CreateLifestyleManager(activator);
            EnsureDependenciesCanBeSatisfied(activator as IDependencyAwareActivator);

            if (AllRequiredDependenciesResolvable())
            {
                SetNewState(HandlerState.Valid);
                DisconnectEvents();
                missingDependencies = null;
            }
        }
		/// <summary>
		///   Saves the kernel instance, subscribes to
		///   <see cref = "IKernelEvents.AddedAsChildKernel" />
		///   event,
		///   creates the lifestyle manager instance and computes
		///   the handler state.
		/// </summary>
		/// <param name = "kernel"></param>
		public virtual void Init(IKernel kernel)
		{
			if (kernel == null)
			{
				throw new ArgumentNullException("kernel");
			}
			this.kernel = kernel as IKernelInternal;
			if (this.kernel == null)
			{
				throw new HandlerException(
					string.Format("The kernel does not implement {0}. It must also provide contract for internal usage.",
					              typeof(IKernelInternal).FullName));
			}
			this.kernel.AddedAsChildKernel += OnAddedAsChildKernel;

			var activator = this.kernel.CreateComponentActivator(ComponentModel);
			lifestyleManager = CreateLifestyleManager(activator);
			EnsureDependenciesCanBeSatisfied(activator as IDependencyAwareActivator);

			if (state == HandlerState.Valid)
			{
				DisconnectEvents();
			}
		}
Example #10
0
 /// <summary>
 /// Registers for eviction.
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <param name="model">The ComponentModel.</param>
 /// <param name="instance">The instance.</param>
 public void RegisterForEviction(ILifestyleManager manager, ComponentModel model, object instance)
 {
     ScopeLifestyleModule.RegisterForSessionEviction((ScopeLifestyleManager)manager, model, instance);
 }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="real"></param>
 public ProxyLifestyleManager(ILifestyleManager real)
 {
     Guard.NotNull(real, "real");
     Real = real;
     Init(real.Activator, real.Kernel, real.Info, real.OnDestroying, real.OnFetch);
 }
Example #12
0
 /// <summary>
 /// Registers for eviction.
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <param name="model">The ComponentModel.</param>
 /// <param name="instance">The instance.</param>
 public void RegisterForEviction(ILifestyleManager manager, ComponentModel model, object instance)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Example #13
0
		/// <summary>
		///   Saves the kernel instance, subscribes to
		///   <see cref = "IKernelEvents.AddedAsChildKernel" />
		///   event,
		///   creates the lifestyle manager instance and computes
		///   the handler state.
		/// </summary>
		/// <param name = "kernel"></param>
		public virtual void Init(IKernelInternal kernel)
		{
			if (kernel == null)
			{
				throw new ArgumentNullException("kernel");
			}
			this.kernel = kernel;
			this.kernel.AddedAsChildKernel += OnAddedAsChildKernel;

			var activator = this.kernel.CreateComponentActivator(ComponentModel);
			lifestyleManager = CreateLifestyleManager(activator);
			EnsureDependenciesCanBeSatisfied(activator as IDependencyAwareActivator);

			if (AllRequiredDependenciesResolvable())
			{
				SetNewState(HandlerState.Valid);
				DisconnectEvents();
				missingDependencies = null;
			}
		}
Example #14
0
 public void Register(Type serviceType, Func <object> lambdaResolve, ILifestyleManager lifeStyleManager, string registrationId)
 {
     throw new NotImplementedException();
 }
Example #15
0
 public void Register(Type serviceType, Type componentType, ILifestyleManager lifeStyleManager, string registrationId)
 {
     throw new NotImplementedException();
 }
Example #16
0
 /// <summary>
 /// Registers for eviction.
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <param name="model">The model.</param>
 /// <param name="instance">The instance.</param>
 public void RegisterForEviction(ILifestyleManager manager, ComponentModel model, object instance)
 {
 }
Example #17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="real"></param>
 public ProxyLifestyleManager(ILifestyleManager real)
 {
     Guard.NotNull(real, "real");
     Real = real;
     Init(real.Activator, real.Kernel, real.Info, real.OnDestroying,real.OnFetch);
 }
Example #18
0
 public PerRequestLifeStyleManager()
 {
     _perWebRequestLifestyleManager = new ScopedLifestyleManager(new WebRequestScopeAccessor());
     _perThreadLifestyleManager     = new ScopedLifestyleManager(new ThreadScopeAccessor());
 }