Castle.MicroKernel.Handlers.AbstractHandler.CreateLifestyleManager C# (CSharp) Method

CreateLifestyleManager() protected method

Creates an implementation of ILifestyleManager based on LifestyleType and invokes ILifestyleManager.Init to initialize the newly created manager.
protected CreateLifestyleManager ( IComponentActivator activator ) : ILifestyleManager
activator IComponentActivator
return ILifestyleManager
		protected virtual ILifestyleManager CreateLifestyleManager(IComponentActivator activator)
		{
			ILifestyleManager manager = null;

			LifestyleType type = ComponentModel.LifestyleType;

			if (type == LifestyleType.Undefined || type == LifestyleType.Singleton)
			{
				manager = new SingletonLifestyleManager();
			}
			else if (type == LifestyleType.Thread)
			{
				manager = new PerThreadLifestyleManager();
			}
			else if (type == LifestyleType.Transient)
			{
				manager = new TransientLifestyleManager();
			}
			else if (type == LifestyleType.PerWebRequest)
			{
				manager = new PerWebRequestLifestyleManager();
			}
			else if (type == LifestyleType.Custom)
			{
				manager = (ILifestyleManager)
						  Activator.CreateInstance(ComponentModel.CustomLifestyle);
			}
			else if (type == 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 PoolableLifestyleManager(initial, maxSize);
			}

			manager.Init(activator, Kernel, model);

			return manager;
		}