Example #1
0
 public DefaultPool(int initialSize, int maxsize, IComponentActivator componentActivator)
 {
     available               = new Stack <Burden>(initialSize);
     this.initialSize        = initialSize;
     this.maxsize            = maxsize;
     this.componentActivator = componentActivator;
 }
        public Burden ActivateNewInstance(IComponentActivator componentActivator, bool trackedExternally)
        {
            ResolutionContext resolutionContext;

            try
            {
                resolutionContext = resolutionStack.Peek();
            }
            catch (InvalidOperationException)
            {
                throw new ComponentActivatorException(
                          "Not in a resolution context. 'ActivateNewInstance' method can only be called withing a resoltion scope. (after 'EnterResolutionContext' was called within a handler)");
            }

            var activator = componentActivator as IDependencyAwareActivator;

            if (activator != null)
            {
                trackedExternally |= activator.IsManagedExternally(resolutionContext.Handler.ComponentModel);
            }

            var burden = resolutionContext.CreateBurden(trackedExternally);

            burden.SetRootInstance(componentActivator.Create(this));
            return(burden);
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref = "CreateOnUIThreadActivator" /> class.
 /// </summary>
 /// <param name = "model">The model.</param>
 /// <param name = "kernel">The kernel.</param>
 /// <param name = "onCreation">Delegate called on construction.</param>
 /// <param name = "onDestruction">Delegate called on destruction.</param>
 public CreateOnUIThreadActivator(ComponentModel model, IKernel kernel, ComponentInstanceDelegate onCreation,
                                  ComponentInstanceDelegate onDestruction)
     : base(model, kernel, onCreation, onDestruction)
 {
     customActivator = CreateCustomActivator(model, kernel);
     performCreation = PerformCreation;
 }
Example #4
0
		public DefaultPool(int initialSize, int maxsize, IComponentActivator componentActivator)
		{
			available = new Stack<Burden>(initialSize);
			this.initialSize = initialSize;
			this.maxsize = maxsize;
			this.componentActivator = componentActivator;
		}
		/// <summary>
		///   Initializes a new instance of the <see cref = "CreateOnUIThreadActivator" /> class.
		/// </summary>
		/// <param name = "model">The model.</param>
		/// <param name = "kernel">The kernel.</param>
		/// <param name = "onCreation">Delegate called on construction.</param>
		/// <param name = "onDestruction">Delegate called on destruction.</param>
		public CreateOnUIThreadActivator(ComponentModel model, IKernel kernel, ComponentInstanceDelegate onCreation,
		                                 ComponentInstanceDelegate onDestruction)
			: base(model, kernel, onCreation, onDestruction)
		{
			customActivator = CreateCustomActivator(model, kernel);
			performCreation = PerformCreation;
		}
Example #6
0
        public DefaultContainer(ILocator componentLocator)
        {
            this.componentLocator = componentLocator;

            this.componentRegistry  = new DefaultComponentRegistry();
            this.componentCache     = new DefaultComponentCache();
            this.componentActivator = new DefaultComponentActivator(this.componentRegistry, this.componentCache);
        }
Example #7
0
		public DefaultPool(int initialsize, int maxsize, IComponentActivator componentActivator)
		{
			this.initialsize = initialsize;
			this.maxsize = maxsize;
			this.componentActivator = componentActivator;

			InitPool();
		}
Example #8
0
		public DefaultPool(int initialsize, int maxsize, IComponentActivator componentActivator, IKernel kernel)
		{
			this.initialsize = initialsize;
			this.maxsize = maxsize;
			this.componentActivator = componentActivator;
			this.kernel = kernel;

			InitPool();
		}
Example #9
0
        /// <summary>
        ///   Creates an implementation of
        ///   <see cref = "ILifestyleManager" />
        ///   based
        ///   on
        ///   <see cref = "LifestyleType" />
        ///   and invokes
        ///   <see cref = "ILifestyleManager.Init" />
        ///   to initialize the newly created manager.
        /// </summary>
        /// <param name = "activator"></param>
        /// <returns></returns>
        protected virtual ILifestyleManager CreateLifestyleManager(IComponentActivator activator)
        {
            ILifestyleManager manager;
            var type = ComponentModel.LifestyleType;

            switch (type)
            {
            case LifestyleType.Thread:
#if SILVERLIGHT
                manager = new PerThreadThreadStaticLifestyleManager();
#else
                manager = new PerThreadLifestyleManager();
#endif
                break;

            case LifestyleType.Transient:
                manager = new TransientLifestyleManager();
                break;

#if (!SILVERLIGHT && !CLIENTPROFILE)
            case LifestyleType.PerWebRequest:
                manager = new PerWebRequestLifestyleManager();
                break;
#endif
            case LifestyleType.Custom:
                manager = ComponentModel.CustomLifestyle.CreateInstance <ILifestyleManager>();

                break;

            case LifestyleType.Pooled:
            {
                var initial = ExtendedPropertiesConstants.Pool_Default_InitialPoolSize;
                var 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);
            }
            break;

            default:
                //this includes LifestyleType.Undefined, LifestyleType.Singleton and invalid values
                manager = new SingletonLifestyleManager();
                break;
            }

            manager.Init(activator, Kernel, model);

            return(manager);
        }
Example #10
0
        public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
        {
            base.Init(componentActivator, kernel, model);

            manager = kernel.GetSubSystem("scope") as IScopeManager;
            if (manager == null)
            {
                throw new InvalidOperationException("Scope Subsystem not found.  Did you forget to add it?");
            }
        }
		public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
		{
			base.Init(componentActivator, kernel, model);

			manager = kernel.GetSubSystem("scope") as IScopeManager;
			if (manager == null)
			{
				throw new InvalidOperationException("Scope Subsystem not found.  Did you forget to add it?");
			}
		}
Example #12
0
        public DefaultPool(int initialsize, int maxsize, IComponentActivator componentActivator)
        {
            this.initialsize        = initialsize;
            this.maxsize            = maxsize;
            this.componentActivator = componentActivator;

            this.rwlock = new ReaderWriterLock();

            InitPool();
        }
Example #13
0
 public Registration(
     IComponentDescriptor descriptor,
     IComponentActivator activator,
     IEnumerable <IParameter> parameters,
     ComponentLifestyle lifestyle)
 {
     _descriptor = Enforce.ArgumentNotNull(descriptor, "descriptor");
     _activator  = Enforce.ArgumentNotNull(activator, "activator");
     _lifestyle  = lifestyle;
     _scope      = scope.InstanceScopeFactory.ToScope(lifestyle);
 }
Example #14
0
        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 #15
0
        public DefaultPool(int initialsize, int maxsize, IComponentActivator componentActivator)
        {
            this.initialsize        = initialsize;
            this.maxsize            = maxsize;
            this.componentActivator = componentActivator;

            this.rwlock = new ReaderWriterLock();

            // Thread thread = new Thread(new ThreadStart(InitPool));
            // thread.Start();
            InitPool();
        }
Example #16
0
		public DefaultPool(int initialsize, int maxsize, IComponentActivator componentActivator)
		{
			this.initialsize = initialsize;
			this.maxsize = maxsize;
			this.componentActivator = componentActivator;

			this.rwlock = new ReaderWriterLock();

			// Thread thread = new Thread(new ThreadStart(InitPool));
			// thread.Start();
			InitPool();
		}
		public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
		{
			base.Init(componentActivator, kernel, model);

			// check ILoggerFactory is registered (logging is enabled)
			if (kernel.HasComponent(typeof(ILoggerFactory))) 
			{
				// get logger factory instance
				ILoggerFactory loggerFactory = kernel.Resolve<ILoggerFactory>();
				// create logger
				_Logger = loggerFactory.Create(GetType());
			}
			else
				_Logger = NullLogger.Instance;
		}
		public object GetInstance(CreationContext context, IComponentActivator activator)
		{
			if (perThreadLookup == null)
			{
				perThreadLookup = new Dictionary<IComponentActivator, object>();
			}
			object instance;
			if (!perThreadLookup.TryGetValue(activator, out instance))
			{
				instance = activator.Create(context);
				perThreadLookup.Add(activator, instance);
				perContainerLookup.Add(activator, instance);
			}

			return instance;
		}
        public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
        {
            Contract.Ensures(_Lifestyle1 != null);
            Contract.Ensures(Initialized);

            // check ILoggerFactory is registered
            if (kernel.HasComponent(typeof(ILoggerFactory)))
            {
                // get logger factory instance
                var loggerFactory = kernel.Resolve <ILoggerFactory>();
                // create logger
                _Logger = loggerFactory.Create(typeof(WrapperResolveLifestyleManager <T>));
            }
            else
            {
                _Logger = NullLogger.Instance;
            }

            if (_Logger.IsDebugEnabled)
            {
                _Logger.DebugFormat("initializing (for component: {0})", string.Join(",", model.Services));
            }

            _LifestyleKernel.Register(Component.For <T>().LifeStyle.Transient.Named("T.lifestyle"));
            kernel.AddChildKernel(_LifestyleKernel);

            try
            {
                _Lifestyle1 = _LifestyleKernel.Resolve <T>();
            }
            finally
            {
                kernel.RemoveChildKernel(_LifestyleKernel);
            }

            _Lifestyle1.Init(componentActivator, kernel, model);

            base.Init(componentActivator, kernel, model);

            Contract.Assume(_Lifestyle1 != null,
                            "lifestyle1 can't be null because the Resolve<T> call will throw an exception if a matching service wasn't found");

            _Logger.Debug("initialized");

            _Initialized = true;
        }
        public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
        {
            base.Init(componentActivator, kernel, model);

            // check ILoggerFactory is registered (logging is enabled)
            if (kernel.HasComponent(typeof(ILoggerFactory)))
            {
                // get logger factory instance
                ILoggerFactory loggerFactory = kernel.Resolve <ILoggerFactory>();
                // create logger
                _Logger = loggerFactory.Create(GetType());
            }
            else
            {
                _Logger = NullLogger.Instance;
            }
        }
Example #21
0
    public Renderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IComponentActivator componentActivator)
    {
        if (serviceProvider is null)
        {
            throw new ArgumentNullException(nameof(serviceProvider));
        }

        if (loggerFactory is null)
        {
            throw new ArgumentNullException(nameof(loggerFactory));
        }

        // Even though IComponentActivator is not marked as nullable, we do allow null because that's how the framework internally indicates
        // that we should use default activation logic.

        _serviceProvider  = serviceProvider;
        _logger           = loggerFactory.CreateLogger <Renderer>();
        _componentFactory = new ComponentFactory(componentActivator);
    }
Example #22
0
        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 #23
0
    public Renderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IComponentActivator componentActivator)
    {
        if (serviceProvider is null)
        {
            throw new ArgumentNullException(nameof(serviceProvider));
        }

        if (loggerFactory is null)
        {
            throw new ArgumentNullException(nameof(loggerFactory));
        }

        if (componentActivator is null)
        {
            throw new ArgumentNullException(nameof(componentActivator));
        }

        _serviceProvider  = serviceProvider;
        _logger           = loggerFactory.CreateLogger <Renderer>();
        _componentFactory = new ComponentFactory(componentActivator);
    }
Example #24
0
        public virtual IComponentActivator CreateComponentActivator(ComponentModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            IComponentActivator activator = null;

            if (model.CustomComponentActivator == null)
            {
                activator = new DefaultComponentActivator(model, this,
                                                          new ComponentInstanceDelegate(RaiseComponentCreated),
                                                          new ComponentInstanceDelegate(RaiseComponentDestroyed));
            }
            else
            {
                try
                {
                    activator = (IComponentActivator)
                                Activator.CreateInstance(model.CustomComponentActivator,
                                                         new object[]
                    {
                        model, this,
                        new ComponentInstanceDelegate(RaiseComponentCreated),
                        new ComponentInstanceDelegate(RaiseComponentDestroyed)
                    });
                }
                catch (Exception e)
                {
                    throw new KernelException("Could not instantiate custom activator", e);
                }
            }

            return(activator);
        }
Example #25
0
 public Resolver(IComponentActivator activator, IComponentLookup componentLookup)
 {
     this.activator = activator;
     this.componentLookup = componentLookup;
 }
Example #26
0
		public Burden ActivateNewInstance(IComponentActivator componentActivator, bool trackedExternally)
		{
			ResolutionContext resolutionContext;
			try
			{
				resolutionContext = resolutionStack.Peek();
			}
			catch (InvalidOperationException)
			{
				throw new ComponentActivatorException(
					"Not in a resolution context. 'ActivateNewInstance' method can only be called withing a resoltion scope. (after 'EnterResolutionContext' was called within a handler)");
			}

			var activator = componentActivator as IDependencyAwareActivator;
			if (activator != null)
			{
				trackedExternally |= activator.IsManagedExternally(resolutionContext.Handler.ComponentModel);
			}

			var burden = resolutionContext.CreateBurden(trackedExternally);
			burden.SetRootInstance(componentActivator.Create(this));
			return burden;
		}
        /// <summary>
        /// Inits the specified component activator.
        /// </summary>
        /// <param name="componentActivator">The component activator.</param>
        /// <param name="kernel">The kernel.</param>
        public override void Init(IComponentActivator componentActivator, IKernel kernel)
        {
            base.Init(componentActivator, kernel);

            _requestScope = Kernel[typeof(IRequestScope)] as IRequestScope;
        }
Example #28
0
 public IPool Create(int initialsize, int maxSize, IComponentActivator activator)
 {
     return(new EmptyPool());
 }
		public virtual void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
		{
			this.componentActivator = componentActivator;
			this.kernel = kernel;
			this.model = model;
		}
Example #30
0
        public Renderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IComponentActivator componentActivator)
        {
            if (serviceProvider is null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            if (loggerFactory is null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (componentActivator is null)
            {
                throw new ArgumentNullException(nameof(componentActivator));
            }

            _serviceProvider  = serviceProvider;
            _logger           = loggerFactory.CreateLogger <Renderer>();
            _componentFactory = new ComponentFactory(componentActivator);

            if (TestableMetadataUpdate.IsSupported)
            {
                HotReloadManager.OnDeltaApplied += RenderRootComponentsOnHotReload;
            }
        }
 public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
 {
     lifestyle1.Init(componentActivator, kernel, model);
     lifestyle2.Init(componentActivator, kernel, model);
 }
		public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
		{
			base.Init(componentActivator, kernel, model);
		}
		/// <summary>
		///   Creates an implementation of
		///   <see cref = "ILifestyleManager" />
		///   based
		///   on
		///   <see cref = "LifestyleType" />
		///   and invokes
		///   <see cref = "ILifestyleManager.Init" />
		///   to initialize the newly created manager.
		/// </summary>
		/// <param name = "activator"></param>
		/// <returns></returns>
		protected virtual ILifestyleManager CreateLifestyleManager(IComponentActivator activator)
		{
			ILifestyleManager manager = null;

			LifestyleType type = ComponentModel.LifestyleType;

			switch (type)
			{
				case LifestyleType.Thread:
#if (!SILVERLIGHT)
					manager = new PerThreadLifestyleManager();
#else
					manager = new PerThreadThreadStaticLifestyleManager();
#endif
					break;
				case LifestyleType.Transient:
					manager = new TransientLifestyleManager();
					break;
#if (!SILVERLIGHT)
				case LifestyleType.PerWebRequest:
					manager = new PerWebRequestLifestyleManager();
					break;
#endif
				case LifestyleType.Custom:
					manager = (ILifestyleManager)Activator.CreateInstance(ComponentModel.CustomLifestyle);
					break;
				case 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);
				}
					break;
				default:
					//this includes LifestyleType.Undefined, LifestyleType.Singleton and invalid values
					manager = new SingletonLifestyleManager();
					break;
			}

			manager.Init(activator, Kernel, model);

			return manager;
		}
		public IPool Create(int initialsize, int maxSize, IComponentActivator activator)
		{
			return new DefaultPool(initialsize, maxSize, activator);
		}
Example #35
0
		/// <summary>
		/// Creates an implementation of <see cref="ILifestyleManager"/> based
		/// on <see cref="LifestyleType"/> and invokes <see cref="ILifestyleManager.Init"/>
		/// to initialize the newly created manager.
		/// </summary>
		/// <param name="activator"></param>
		/// <returns></returns>
		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;
		}
		/// <summary>
		///   Creates an implementation of
		///   <see cref = "ILifestyleManager" />
		///   based
		///   on
		///   <see cref = "LifestyleType" />
		///   and invokes
		///   <see cref = "ILifestyleManager.Init" />
		///   to initialize the newly created manager.
		/// </summary>
		/// <param name = "activator"></param>
		/// <returns></returns>
		protected virtual ILifestyleManager CreateLifestyleManager(IComponentActivator activator)
		{
			ILifestyleManager manager;
			var type = ComponentModel.LifestyleType;

			switch (type)
			{
				case LifestyleType.Scoped:
					var scopeManager = Kernel.GetSubSystem("scope") as IScopeManager;
					if (scopeManager == null)
					{
						throw new InvalidOperationException("Scope Subsystem not found.  Did you forget to add it?");
					}
					manager = new ScopedLifestyleManager(new CurrentScopeAccessor(scopeManager, ComponentModel));
					break;
				case LifestyleType.Thread:
#if SILVERLIGHT
					manager = new PerThreadThreadStaticLifestyleManager();
#else
					manager = new PerThreadLifestyleManager();
#endif
					break;
				case LifestyleType.Transient:
					manager = new TransientLifestyleManager();
					break;
#if (!SILVERLIGHT && !CLIENTPROFILE)
				case LifestyleType.PerWebRequest:
					manager = new PerWebRequestLifestyleManager();
					break;
#endif
				case LifestyleType.Custom:
					manager = ComponentModel.CustomLifestyle.CreateInstance<ILifestyleManager>();

					break;
				case LifestyleType.Pooled:
				{
					var initial = ExtendedPropertiesConstants.Pool_Default_InitialPoolSize;
					var 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);
				}
					break;
				default:
					//this includes LifestyleType.Undefined, LifestyleType.Singleton and invalid values
					manager = new SingletonLifestyleManager();
					break;
			}

			manager.Init(activator, Kernel, ComponentModel);

			return manager;
		}
        /// <summary>
        ///   Creates an implementation of
        ///   <see cref = "ILifestyleManager" />
        ///   based
        ///   on
        ///   <see cref = "LifestyleType" />
        ///   and invokes
        ///   <see cref = "ILifestyleManager.Init" />
        ///   to initialize the newly created manager.
        /// </summary>
        /// <param name = "activator"></param>
        /// <returns></returns>
        protected virtual ILifestyleManager CreateLifestyleManager(IComponentActivator activator)
        {
            ILifestyleManager manager;
            var type = ComponentModel.LifestyleType;

            switch (type)
            {
            case LifestyleType.Scoped:
                var scopeManager = Kernel.GetSubSystem("scope") as IScopeManager;
                if (scopeManager == null)
                {
                    throw new InvalidOperationException("Scope Subsystem not found.  Did you forget to add it?");
                }
                manager = new ScopedLifestyleManager(new CurrentScopeAccessor(scopeManager, ComponentModel));
                break;

            case LifestyleType.Thread:
#if SILVERLIGHT
                manager = new PerThreadThreadStaticLifestyleManager();
#else
                manager = new PerThreadLifestyleManager();
#endif
                break;

            case LifestyleType.Transient:
                manager = new TransientLifestyleManager();
                break;

#if (!SILVERLIGHT && !CLIENTPROFILE)
            case LifestyleType.PerWebRequest:
                manager = new PerWebRequestLifestyleManager();
                break;
#endif
            case LifestyleType.Custom:
                manager = ComponentModel.CustomLifestyle.CreateInstance <ILifestyleManager>();

                break;

            case LifestyleType.Pooled:
            {
                var initial = ExtendedPropertiesConstants.Pool_Default_InitialPoolSize;
                var 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);
            }
            break;

            default:
                //this includes LifestyleType.Undefined, LifestyleType.Singleton and invalid values
                manager = new SingletonLifestyleManager();
                break;
            }

            manager.Init(activator, Kernel, ComponentModel);

            return(manager);
        }
		public LazyComponentInterceptor(IComponentActivator activator, CreationContext context)
		{
			this.activator = activator;
			this.context = context;
		}
        public override void Init(IComponentActivator componentActivator, IKernel kernel)
        {
            base.Init(componentActivator, kernel);

            pool = InitPool(initialSize, maxSize);
        }
Example #40
0
 public ComponentFactory(IComponentActivator componentActivator)
 {
     _componentActivator = componentActivator ?? throw new ArgumentNullException(nameof(componentActivator));
 }
		public LazyComponentActivator(ComponentModel model, IComponentActivator innerActivator)
		{
			this.innerActivator = innerActivator;
			this.model = model;
		}
 public void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
 {
     activator = componentActivator;
 }
Example #43
0
 public Resolver(IComponentActivator activator, IComponentLookup componentLookup)
 {
     this.activator       = activator;
     this.componentLookup = componentLookup;
 }
		public override void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
		{
			base.Init(componentActivator, kernel, model);

			pool = CreatePool(initialSize, maxSize);
		}
Example #45
0
 public void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
 {
     _perWebRequestLifestyleManager.Init(componentActivator, kernel, model);
     _perThreadLifestyleManager.Init(componentActivator, kernel, model);
 }
Example #46
0
        /// <summary>
        ///   Creates an implementation of <see cref = "ILifestyleManager" /> based on <see cref = "LifestyleType" /> and invokes <see cref = "ILifestyleManager.Init" /> to initialize the newly created manager.
        /// </summary>
        /// <param name = "model"> </param>
        /// <param name = "activator"> </param>
        /// <returns> </returns>
        public virtual ILifestyleManager CreateLifestyleManager(ComponentModel model, IComponentActivator activator)
        {
            ILifestyleManager manager;
            var type = model.LifestyleType;

            switch (type)
            {
            case LifestyleType.Scoped:
                manager = new ScopedLifestyleManager(CreateScopeAccessor(model));
                break;

            case LifestyleType.Bound:
                manager = new ScopedLifestyleManager(CreateScopeAccessorForBoundLifestyle(model));
                break;

            case LifestyleType.Thread:
                manager = new ScopedLifestyleManager(new ThreadScopeAccessor());
                break;

            case LifestyleType.Transient:
                manager = new TransientLifestyleManager();
                break;

#if !(SILVERLIGHT || CLIENTPROFILE)
            case LifestyleType.PerWebRequest:
                manager = new ScopedLifestyleManager(new WebRequestScopeAccessor());
                break;
#endif
            case LifestyleType.Custom:
                manager = model.CustomLifestyle.CreateInstance <ILifestyleManager>();

                break;

            case LifestyleType.Pooled:
                var initial = ExtendedPropertiesConstants.Pool_Default_InitialPoolSize;
                var maxSize = ExtendedPropertiesConstants.Pool_Default_MaxPoolSize;

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

                manager = new PoolableLifestyleManager(initial, maxSize);
                break;

            default:
                //this includes LifestyleType.Undefined, LifestyleType.Singleton and invalid values
                manager = new SingletonLifestyleManager();
                break;
            }

            manager.Init(activator, this, model);

            return(manager);
        }
Example #47
0
 public TestRenderer(IServiceProvider serviceProvider, IComponentActivator componentActivator)
     : base(serviceProvider, NullLoggerFactory.Instance, componentActivator)
 {
     Dispatcher = Dispatcher.CreateDefault();
 }
 public IPool Create(int initialsize, int maxSize, IComponentActivator activator)
 {
     return(new DefaultPool(initialsize, maxSize, activator));
 }
 public override ILifestyleManager CreateLifestyleManager(ComponentModel model, IComponentActivator activator)
 {
     if (model.LifestyleType == LifestyleType.PerWebRequest)
     {
         var manager = new ScopedLifestyleManager(new PerRequestScopeAccessor());
         manager.Init(activator, this, model);
         return(manager);
     }
     return(base.CreateLifestyleManager(model, activator));
 }