/// <summary> /// Resolves the component(s) from given kernel. /// </summary> /// <param name = "kernel"></param> /// <param name = "scope"></param> /// <returns>Resolved component(s).</returns> public virtual object Resolve(IKernelInternal kernel, IReleasePolicy scope) { if (LoadByName(kernel)) { try { return(kernel.Resolve(componentName, componentType, additionalArguments, scope)); } catch (ComponentNotFoundException e) { if (actualSelectorType == typeof(DefaultDelegateComponentSelector) && fallbackToResolveByTypeIfNameNotFound == false) { e.Data["breakingChangeId"] = "typedFactoryFallbackToResolveByTypeIfNameNotFound"; e.Data["breakingChange"] = "This exception may have been caused by a breaking change between Windsor 2.5 and 3.0 See breakingchanges.txt for more details."; } throw; } } // Ignore thread-static parent context call stack tracking. Factory-resolved components // are already tracked by the factory itself and should not be added as burdens just because // we happen to be resolving in the call stack of some random component’s constructor. // Specifically, act the same as we would if the timing was slightly different and we were not // resolving within the call stack of the random component’s constructor. return(kernel.Resolve(componentType, additionalArguments, scope, ignoreParentContext: true)); }
private object GetNewInstance(CreationContext context, IReleasePolicy releasePolicy) { var burden = CreateInstance(context, true); cachedBurden = burden; Track(burden, releasePolicy); return burden.Instance; }
public virtual object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var burden = CreateInstance(context, false); Track(burden, releasePolicy); return(burden.Instance); }
public override object Resolve(CreationContext context, Burden burden, IReleasePolicy releasePolicy) { if (cachedBurden != null) { return cachedBurden.Instance; } var instanceFromContext = context.GetContextualProperty(ComponentActivator); if (instanceFromContext != null) { //we've been called recursively, by some dependency from base.Resolve call return instanceFromContext; } object instance; lock (ComponentActivator) { if (cachedBurden != null) { return cachedBurden.Instance; } instance = base.CreateInstance(context, burden); cachedBurden = burden; } Track(burden, releasePolicy); return instance; }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var store = GetStore(); var instance = base.Resolve(context, releasePolicy); if (instance == null) { if (context.Handler.ComponentModel.ExtendedProperties[Constants.REG_IS_INSTANCE_KEY] != null) { throw new DependencyResolutionException("Cannot find the instance in the context store."); } } else if (store[Model.Name] == null) { store[Model.Name] = instance; store.GetContextInstances().Add(new ContextStoreDependency(Model.Name, instance, this)); _isRegisteredForCleanup = true; } if (!_isRegisteredForCleanup) { store.GetContextInstances().Add(new ContextStoreDependency(Model.Name, instance, this)); _isRegisteredForCleanup = true; } return store[Model.Name]; }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var current = HttpContext.Current; if (current == null) throw new InvalidOperationException("HttpContext.Current is null. PerHttpApplicationLifestyle can only be used in ASP.NET"); var app = current.ApplicationInstance; var lifestyleModule = app.Modules .Cast<string>() .Select(k => app.Modules[k]) .OfType<PerHttpApplicationLifestyleModule>() .FirstOrDefault(); if (lifestyleModule == null) { var message = string.Format("Looks like you forgot to register the http module {0}" + "\r\nAdd '<add name=\"PerHttpApplicationLifestyle\" type=\"{1}\" />' " + "to the <httpModules> section on your web.config", typeof (PerWebRequestLifestyleModule).FullName, typeof (PerWebRequestLifestyleModule).AssemblyQualifiedName); throw new Exception(message); } if (!lifestyleModule.HasComponent(PerAppObjectID)) { var instance = base.Resolve(context, releasePolicy); lifestyleModule[PerAppObjectID] = instance; app.Disposed += (sender, args) => base.Release(instance); } return lifestyleModule[PerAppObjectID]; }
protected virtual void Track(Burden burden, IReleasePolicy releasePolicy) { if (burden.RequiresPolicyRelease) { releasePolicy.Track(burden.Instance, burden); } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { // 1. read from cache if (cachedBurden != null) { return(cachedBurden.Instance); } var initializing = false; try { initializing = init.ExecuteThreadSafeOnce(); if (cachedBurden != null) { return(cachedBurden.Instance); } var burden = CreateInstance(context, true); cachedBurden = burden; Track(burden, releasePolicy); return(burden.Instance); } finally { if (initializing) { init.EndThreadSafeOnceSection(); } } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { // 1. read from cache if (cachedBurden != null) { return cachedBurden.Instance; } var initializing = false; try { initializing = init.ExecuteThreadSafeOnce(); if (cachedBurden != null) { return cachedBurden.Instance; } var burden = CreateInstance(context, true); cachedBurden = burden; Track(burden, releasePolicy); return burden.Instance; } finally { if (initializing) { init.EndThreadSafeOnceSection(); } } }
public override object Resolve(CreationContext context, Burden burden, IReleasePolicy releasePolicy) { lock (slot) { var map = (Dictionary<IComponentActivator, object>)Thread.GetData(slot); if (map == null) { map = new Dictionary<IComponentActivator, object>(); Thread.SetData(slot, map); } Object instance; if (!map.TryGetValue(ComponentActivator, out instance)) { instance = base.Resolve(context, burden, releasePolicy); map.Add(ComponentActivator, instance); instances.Add(burden); } return instance; } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var current = HttpContext.Current; if (current == null) { throw new InvalidOperationException("HttpContext.Current is null. PerHttpApplicationLifestyle can only be used in ASP.NET"); } var app = current.ApplicationInstance; var lifestyleModule = app.Modules .Cast <string>() .Select(k => app.Modules[k]) .OfType <PerHttpApplicationLifestyleModule>() .FirstOrDefault(); if (lifestyleModule == null) { var message = string.Format("Looks like you forgot to register the http module {0}" + "\r\nAdd '<add name=\"PerHttpApplicationLifestyle\" type=\"{1}\" />' " + "to the <httpModules> section on your web.config", typeof(PerWebRequestLifestyleModule).FullName, typeof(PerWebRequestLifestyleModule).AssemblyQualifiedName); throw new ConfigurationErrorsException(message); } if (!lifestyleModule.HasComponent(PerAppObjectID)) { var instance = base.Resolve(context, releasePolicy); lifestyleModule[PerAppObjectID] = instance; app.Disposed += (sender, args) => base.Release(instance); } return(lifestyleModule[PerAppObjectID]); }
public virtual object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var burden = CreateInstance(context, false); Track(burden, releasePolicy); return burden.Instance; }
public override object Resolve(CreationContext context, Burden burden, IReleasePolicy releasePolicy) { var current = HttpContext.Current; if (current == null) { throw new InvalidOperationException( "HttpContext.Current is null. PerWebRequestLifestyle can only be used in ASP.Net"); } var cachedBurden = current.Items[PerRequestObjectID]; if (cachedBurden != null) { return cachedBurden; } if (!PerWebRequestLifestyleModule.Initialized) { var message = string.Format( "Looks like you forgot to register the http module {0}{1}Add '<add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor\" />' to the <httpModules> section on your web.config. If you're running IIS7 in Integrated Mode you will need to add it to <modules> section under <system.webServer>", typeof(PerWebRequestLifestyleModule).FullName, Environment.NewLine); throw new Exception(message); } var instance = base.Resolve(context, burden, releasePolicy); current.Items[PerRequestObjectID] = burden; PerWebRequestLifestyleModule.RegisterForEviction(this, burden); return instance; }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { lock (slot) { var map = (Dictionary <IComponentActivator, Burden>)Thread.GetData(slot); if (map == null) { map = new Dictionary <IComponentActivator, Burden>(); Thread.SetData(slot, map); } Burden burden; if (!map.TryGetValue(ComponentActivator, out burden)) { burden = base.CreateInstance(context, true); map.Add(ComponentActivator, burden); instances.Add(burden); Track(burden, releasePolicy); } return(burden.Instance); } }
public virtual object Resolve(CreationContext context, Burden burden, IReleasePolicy releasePolicy) { var instance = CreateInstance(context, burden); Track(burden, releasePolicy); return instance; }
protected virtual Burden PoolCreationCallback(CreationContext context, IReleasePolicy releasePolicy) { var burden = base.CreateInstance(context, false); Track(burden, releasePolicy); return(burden); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { lock (slot) { var map = (Dictionary<IComponentActivator, Burden>)Thread.GetData(slot); if (map == null) { map = new Dictionary<IComponentActivator, Burden>(); Thread.SetData(slot, map); } Burden burden; if (!map.TryGetValue(ComponentActivator, out burden)) { burden = base.CreateInstance(context, true); map.Add(ComponentActivator, burden); instances.Add(burden); Track(burden, releasePolicy); } return burden.Instance; } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { // 1. read from cache if (cachedBurden != null) { return cachedBurden.Instance; } var instanceFromContext = context.GetContextualProperty(ComponentActivator); if (instanceFromContext != null) { //we've been called recursively, by some dependency from base.Resolve call return instanceFromContext; } var initializing = false; try { initializing = init.ExecuteThreadSafeOnce(); if (cachedBurden != null) { return cachedBurden.Instance; } var burden = CreateInstance(context, true); cachedBurden = burden; Track(burden, releasePolicy); return burden.Instance; } finally { if (initializing) { init.EndThreadSafeOnceSection(); } } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var current = HttpContext.Current; if (current == null) { throw new InvalidOperationException( "HttpContext.Current is null. PerWebRequestLifestyle can only be used in ASP.Net"); } var cachedBurden = (Burden)current.Items[perRequestObjectId]; if (cachedBurden != null) { return(cachedBurden.Instance); } PerWebRequestLifestyleModule.EnsureInitialized(); var burden = base.CreateInstance(context, true); current.Items[perRequestObjectId] = burden; PerWebRequestLifestyleModule.RegisterForEviction(this, burden); Track(burden, releasePolicy); return(burden.Instance); }
Array IKernelInternal.ResolveAll(Type service, IDictionary arguments, IReleasePolicy policy) { var resolved = new List <object>(); foreach (var handler in GetHandlers(service)) { if (handler.IsBeingResolvedInContext(currentCreationContext)) { continue; } try { var component = ResolveComponent(handler, service, arguments, policy); resolved.Add(component); } catch (GenericHandlerTypeMismatchException) { // that's the only case where we ignore the component and allow it to not be resolved. // only because we have no way to actually test if generic constraints can be satisfied. } } if (resolved.Count == 0) { EmptyCollectionResolving(service); } var components = Array.CreateInstance(service, resolved.Count); ((ICollection)resolved).CopyTo(components, 0); return(components); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var store = GetStore(); var instance = base.Resolve(context, releasePolicy); if (instance == null) { if (context.Handler.ComponentModel.ExtendedProperties[Constants.REG_IS_INSTANCE_KEY] != null) { throw new DependencyResolutionException("Cannot find the instance in the context store."); } } else if (store[Model.Name] == null) { store[Model.Name] = instance; store.GetContextInstances().Add(new ContextStoreDependency(Model.Name, instance, this)); _isRegisteredForCleanup = true; } if (!_isRegisteredForCleanup) { store.GetContextInstances().Add(new ContextStoreDependency(Model.Name, instance, this)); _isRegisteredForCleanup = true; } return(store[Model.Name]); }
/// <summary> /// Resolves the component(s) from given kernel. /// </summary> /// <param name = "kernel"></param> /// <param name = "scope"></param> /// <returns>Resolved component(s).</returns> public virtual object Resolve(IKernelInternal kernel, IReleasePolicy scope) { if (LoadByName(kernel)) { return(kernel.Resolve(componentName, componentType, additionalArguments, scope)); } return(kernel.Resolve(componentType, additionalArguments, scope)); }
/// <summary> /// Resolves the component(s) from given kernel. /// </summary> /// <param name = "kernel"></param> /// <param name = "scope"></param> /// <returns>Resolved component(s).</returns> public virtual object Resolve(IKernelInternal kernel, IReleasePolicy scope) { if (ComponentName != null && kernel.LoadHandlerByKey(ComponentName, ComponentType, AdditionalArguments) != null) { return kernel.Resolve(ComponentName, ComponentType, AdditionalArguments, scope); } return kernel.Resolve(ComponentType, AdditionalArguments, scope); }
/// <summary> /// Resolves the component(s) from given kernel. /// </summary> /// <param name = "kernel"></param> /// <param name = "scope"></param> /// <returns>Resolved component(s).</returns> public virtual object Resolve(IKernelInternal kernel, IReleasePolicy scope) { if (ComponentName != null && kernel.LoadHandlerByKey(ComponentName, ComponentType, AdditionalArguments) != null) { return(kernel.Resolve(ComponentName, ComponentType, AdditionalArguments, scope)); } return(kernel.Resolve(ComponentType, AdditionalArguments, scope)); }
/// <summary> /// Resolves the component(s) from given kernel. /// </summary> /// <param name = "kernel"></param> /// <param name = "scope"></param> /// <returns>Resolved component(s).</returns> public virtual object Resolve(IKernelInternal kernel, IReleasePolicy scope) { if (LoadByName(kernel)) { return kernel.Resolve(componentName, componentType, additionalArguments, scope); } return kernel.Resolve(componentType, additionalArguments, scope); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { Contract.Requires(Initialized); Contract.Ensures(Contract.Result <object>() != null); var resolve = _Lifestyle1.Resolve(context, releasePolicy); Contract.Assume(resolve != null, "the resolved instance shouldn't be null"); return(resolve); }
protected override void Track(Burden burden, IReleasePolicy releasePolicy) { var track = burden.RequiresPolicyRelease; burden.RequiresPolicyRelease = false; if (track) { releasePolicy.Track(burden.Instance, burden); } }
/// <summary> /// Resolves the component(s) from given kernel. /// </summary> /// <param name = "kernel"></param> /// <param name = "scope"></param> /// <returns>Resolved component(s).</returns> public virtual object Resolve(IKernelInternal kernel, IReleasePolicy scope) { if (kernel.HasComponent(ComponentName) == false) { return kernel.Resolve(ComponentType, AdditionalArguments, scope); } return kernel.Resolve(ComponentName, ComponentType, AdditionalArguments, scope); }
protected CreationContext CreateCreationContext(IHandler handler, Type requestedType, IDictionary additionalArguments, CreationContext parent, IReleasePolicy policy) { return(new CreationContext(handler, policy, requestedType, additionalArguments, ConversionSubSystem, parent)); }
object IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy, bool ignoreParentContext) { var handler = (this as IKernelInternal).LoadHandlerByType(null, service, arguments); if (handler == null) { throw new ComponentNotFoundException(service); } return(ResolveComponent(handler, service, arguments, policy, ignoreParentContext)); }
public void Release(IReleasePolicy policy) { if (policy == null) throw new ArgumentNullException("policy"); handler.Release(instance); foreach(Burden child in children) { policy.Release(child.instance); } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var result = _container.Get(_perWebRequestObjectId); if (result == null) { result = base.Resolve(context, releasePolicy); _container.Set(_perWebRequestObjectId, result); } return(result); }
/// <summary> /// Constructs a DefaultKernel with the specified /// implementation of <see cref = "IProxyFactory" /> and <see cref = "IDependencyResolver" /> /// </summary> /// <param name = "resolver"></param> /// <param name = "proxyFactory"></param> public DefaultKernel(IDependencyResolver resolver, IProxyFactory proxyFactory) { RegisterSubSystems(); releasePolicy = new LifecycledComponentsReleasePolicy(); handlerFactory = new DefaultHandlerFactory(this); ComponentModelFactory = new DefaultComponentModelFactory(this); this.proxyFactory = proxyFactory; this.resolver = resolver; resolver.Initialize(this, RaiseDependencyResolving); }
/// <summary> /// Initializes a new instance of the <see cref="CreationContext"/> class. /// </summary> /// <param name="handler">The handler.</param> /// <param name="releasePolicy">The release policy.</param> /// <param name="typeToExtractGenericArguments">The type to extract generic arguments.</param> /// <param name="additionalArguments">The additional arguments.</param> /// <param name="conversionManager">The conversion manager.</param> public CreationContext(IHandler handler, IReleasePolicy releasePolicy, Type typeToExtractGenericArguments, IDictionary additionalArguments, ITypeConverter conversionManager) { this.handler = handler; this.releasePolicy = releasePolicy; this.additionalArguments = additionalArguments; this.converter = conversionManager; dependencies = new DependencyModelCollection(); genericArguments = ExtractGenericArguments(typeToExtractGenericArguments); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { if (MsLifetimeScope.Current == null) { //Act as transient! var burden = CreateInstance(context, false); Track(burden, releasePolicy); return(burden.Instance); } return(base.Resolve(context, releasePolicy)); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { if (MsLifetimeScope.Current == null) { return(base.Resolve(context, releasePolicy)); } using (MsLifetimeScope.Using(_globalMsLifetimeScopeProvider.LifetimeScope)) { return(base.Resolve(context, releasePolicy)); } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var scope = GetScope(context); var burden = scope.GetCachedInstance(Model, afterCreated => { var localBurden = base.CreateInstance(context, trackedExternally: true); afterCreated(localBurden); Track(localBurden, releasePolicy); return localBurden; }); return burden.Instance; }
object IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) { throw new NotImplementedException(); /*var handler = (this as IKernelInternal).LoadHandlerByType(null, service, arguments); * if (handler == null) * { * //throw new ComponentNotFoundException(key, service, otherHandlers); * throw new ArgumentOutOfRangeException(service.ToString()); * } * return ResolveComponent(handler, service, arguments, policy);*/ }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var scope = accessor.GetScope(context); var burden = scope.GetCachedInstance(Model, afterCreated => { var localBurden = base.CreateInstance(context, trackedExternally: true); afterCreated(localBurden); Track(localBurden, releasePolicy); return(localBurden); }); return(burden.Instance); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var scope = accessor.GetScopeCache(context); var burden = scope[this]; if (burden != null) { return burden.Instance; } burden = base.CreateInstance(context, trackedExternally: true); scope[this] = burden; Track(burden, releasePolicy); return burden.Instance; }
public bool Release(IReleasePolicy policy) { if (policy == null) throw new ArgumentNullException("policy"); if (handler.Release(instance) == false) return false; foreach (Burden child in children) { policy.Release(child.instance); } return true; }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { HttpContext current = HttpContext.Current; if (null == current || current.ApplicationInstance == null || current.Session == null) { // Fall back to transient behavior if not in web context. return fallback.Resolve(context, releasePolicy); } else { return base.Resolve(context, releasePolicy); } }
public override object Resolve(CreationContext context, Burden burden, IReleasePolicy releasePolicy) { Burden cachedBurden; var dictionary = Map; if (dictionary.TryGetValue(ComponentActivator, out cachedBurden)) { return burden.Instance; } var instance = base.Resolve(context, burden, releasePolicy); dictionary.Add(ComponentActivator, burden); return instance; }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { HttpContext current = HttpContext.Current; if (null == current || current.ApplicationInstance == null || current.Session == null) { // Fall back to transient behavior if not in web context. return(fallback.Resolve(context, releasePolicy)); } else { return(base.Resolve(context, releasePolicy)); } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var scope = accessor.GetScopeCache(context); var burden = scope[this]; if (burden != null) { return(burden.Instance); } burden = base.CreateInstance(context, trackedExternally: true); scope[this] = burden; Track(burden, releasePolicy); return(burden.Instance); }
/// <summary> /// Initializes a new instance of the <see cref = "ParentHandlerWrapper" /> class. /// </summary> /// <param name = "parentHandler">The parent handler.</param> /// <param name = "childResolver">The child resolver.</param> /// <param name="parentReleasePolicy">Release policy of the parent container.</param> public ParentHandlerWrapper(IHandler parentHandler, ISubDependencyResolver childResolver, IReleasePolicy parentReleasePolicy) { if (parentHandler == null) { throw new ArgumentNullException("parentHandler"); } if (childResolver == null) { throw new ArgumentNullException("childResolver"); } this.parentHandler = parentHandler; this.childResolver = childResolver; this.parentReleasePolicy = parentReleasePolicy; }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var httpContext = ContextProvider(); if (httpContext == null) throw new InvalidOperationException("HttpContext.Current is null. PerWebSessionLifestyle can only be used in ASP.Net"); var session = httpContext.Session; if (session == null) throw new InvalidOperationException("ASP.NET session not found"); if (session[objectID] == null) { var instance = base.Resolve(context, releasePolicy); session[objectID] = instance; return instance; } return session[objectID]; }
/// <summary> /// Constructs a DefaultKernel with the specified /// implementation of <see cref="IProxyFactory"/> /// </summary> public DefaultKernel(IProxyFactory proxyFactory) { this.proxyFactory = proxyFactory; this.childKernels = new ArrayList(); this.facilities = new ArrayList(); this.subsystems = new Hashtable(); RegisterSubSystems(); this.releaserPolicy = new LifecycledComponentsReleasePolicy(); this.handlerFactory = new DefaultHandlerFactory(this); this.modelBuilder = new DefaultComponentModelBuilder(this); this.resolver = new DefaultDependencyResolver(this); this.resolver.Initialize(new DependencyDelegate(RaiseDependencyResolving)); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { if (HttpContext.Current != null) { _component = HttpContext.Current.Session[_perSessionObjectId] ?? (HttpContext.Current.Session[_perSessionObjectId] = base.Resolve(context, releasePolicy)); } else { if (!StaticObjects.ContainsKey(_perSessionObjectId)) { StaticObjects[_perSessionObjectId] = base.Resolve(context, releasePolicy); } _component = StaticObjects[_perSessionObjectId]; } return(_component); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { Burden cachedBurden; var dictionary = Map; if (dictionary.TryGetValue(ComponentActivator, out cachedBurden)) { return cachedBurden.Instance; } var burden = CreateInstance(context, true); dictionary.Add(ComponentActivator, burden); lock(@lock) { instances.Add(burden); } Track(burden, releasePolicy); return burden.Instance; }
/// <summary> /// Initializes a new instance of the <see cref = "CreationContext" /> class. /// </summary> /// <param name = "handler">The handler.</param> /// <param name = "releasePolicy">The release policy.</param> /// <param name = "requestedType">The type to extract generic arguments.</param> /// <param name = "additionalArguments">The additional arguments.</param> /// <param name = "converter">The conversion manager.</param> /// <param name = "parent">Parent context</param> public CreationContext(IHandler handler, IReleasePolicy releasePolicy, Type requestedType, IDictionary additionalArguments, ITypeConverter converter, CreationContext parent) { this.requestedType = requestedType; this.handler = handler; this.releasePolicy = releasePolicy; this.additionalArguments = EnsureAdditionalArgumentsWriteable(additionalArguments); this.converter = converter; if (parent != null) { resolutionStack = parent.resolutionStack; handlerStack = parent.handlerStack; return; } handlerStack = new Stack <IHandler>(4); resolutionStack = new Stack <ResolutionContext>(4); }
/// <summary> /// Initializes a new instance of the <see cref = "CreationContext" /> class. /// </summary> /// <param name = "handler">The handler.</param> /// <param name = "releasePolicy">The release policy.</param> /// <param name = "requestedType">The type to extract generic arguments.</param> /// <param name = "additionalArguments">The additional arguments.</param> /// <param name = "converter">The conversion manager.</param> /// <param name = "parent">Parent context</param> public CreationContext(IHandler handler, IReleasePolicy releasePolicy, Type requestedType, IDictionary additionalArguments, ITypeConverter converter, CreationContext parent) { this.requestedType = requestedType; this.handler = handler; this.releasePolicy = releasePolicy; this.additionalArguments = EnsureAdditionalArgumentsWriteable(additionalArguments); this.converter = converter; if (parent != null) { resolutionStack = parent.resolutionStack; handlerStack = parent.handlerStack; return; } handlerStack = new Stack<IHandler>(4); resolutionStack = new Stack<ResolutionContext>(4); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var scope = GetCurrentScope(); if (scope == null) { throw new ComponentResolutionException( string.Format( "Component '{0}' has scoped lifestyle, and it could not be resolved because no scope is accessible. Did you forget to call container.BeginScope()?", Model.Name), Model); } var cachedBurden = scope.GetComponentBurden(this); if (cachedBurden != null) { return cachedBurden.Instance; } var burden = base.CreateInstance(context, trackedExternally: true); scope.AddComponent(this, burden); Track(burden, releasePolicy); return burden.Instance; }
/// <summary> /// Resolves the component(s) from given kernel. /// </summary> /// <param name = "kernel"></param> /// <param name = "scope"></param> /// <returns>Resolved component(s).</returns> public virtual object Resolve(IKernelInternal kernel, IReleasePolicy scope) { if (LoadByName(kernel)) { try { return(kernel.Resolve(componentName, componentType, additionalArguments, scope)); } catch (ComponentNotFoundException e) { if (actualSelectorType == typeof(DefaultDelegateComponentSelector) && fallbackToResolveByTypeIfNameNotFound == false) { e.Data["breakingChangeId"] = "typedFactoryFallbackToResolveByTypeIfNameNotFound"; e.Data["breakingChange"] = "This exception may have been caused by a breaking change between Windsor 2.5 and 3.0 See breakingchanges.txt for more details."; } throw; } } return(kernel.Resolve(componentType, additionalArguments, scope)); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { Burden cachedBurden; var dictionary = Map; if (dictionary.TryGetValue(ComponentActivator, out cachedBurden)) { return(cachedBurden.Instance); } var burden = CreateInstance(context, true); dictionary.Add(ComponentActivator, burden); lock (@lock) { instances.Add(burden); } Track(burden, releasePolicy); return(burden.Instance); }
/// <summary> /// Resolves the component(s) from given kernel. /// </summary> /// <param name = "kernel"></param> /// <param name = "scope"></param> /// <returns>Resolved component(s).</returns> public virtual object Resolve(IKernelInternal kernel, IReleasePolicy scope) { if (LoadByName(kernel)) { try { return kernel.Resolve(componentName, componentType, additionalArguments, scope); } catch (ComponentNotFoundException e) { if (actualSelectorType == typeof(DefaultDelegateComponentSelector) && fallbackToResolveByTypeIfNameNotFound == false) { e.Data["breakingChangeId"] = "typedFactoryFallbackToResolveByTypeIfNameNotFound"; e.Data["breakingChange"] = "This exception may have been caused by a breaking change between Windsor 2.5 and 3.0 See breakingchanges.txt for more details."; } throw; } } return kernel.Resolve(componentType, additionalArguments, scope); }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { var currentScope = MsLifetimeScope.Current; if (currentScope == null) { //Act as transient! var burden = CreateInstance(context, false); if (!releasePolicy.HasTrack(burden.Instance)) { Track(burden, releasePolicy); } return(burden.Instance); } lock (currentScope) { return(base.Resolve(context, releasePolicy)); } }
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy) { EnsureContainerContextStoreRegistered(); var containerContextStore = Kernel.Resolve<IContainerContextStore>(); var currentContext = containerContextStore.GetCurrent(); if (currentContext == null) { using (new ContainerContext(Kernel)) { return base.Resolve(context, releasePolicy); } } var instance = currentContext.GetInstance(Model.Name, Model.Services.First()); if (instance == null) { instance = base.Resolve(context, releasePolicy); currentContext.Register(Model.Name, Model.Services.First(), instance); } return instance; }