private ILifestyleManager CreateProxyLifestyleManager(IComponentInfo info, ILifestyleManager lifestyleMgr) { if (info.ExtendedProperties.ContainsKey("proxy")) { lifestyleMgr = new ProxyLifestyleManager(lifestyleMgr); } return(lifestyleMgr); }
/// <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(); }
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); }
/// <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(); } }
/// <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); }
/// <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); }
/// <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."); }
/// <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; } }
public void Register(Type serviceType, Func <object> lambdaResolve, ILifestyleManager lifeStyleManager, string registrationId) { throw new NotImplementedException(); }
public void Register(Type serviceType, Type componentType, ILifestyleManager lifeStyleManager, string registrationId) { throw new NotImplementedException(); }
/// <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) { }
/// <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); }
public PerRequestLifeStyleManager() { _perWebRequestLifestyleManager = new ScopedLifestyleManager(new WebRequestScopeAccessor()); _perThreadLifestyleManager = new ScopedLifestyleManager(new ThreadScopeAccessor()); }