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 virtual object Request() { rwlock.AcquireWriterLock(-1); object instance = null; try { if (available.Count != 0) { instance = available.Pop(); if (instance == null) { throw new PoolException("Invalid instance on the pool stack"); } } else { instance = componentActivator.Create(); if (instance == null) { throw new PoolException("Activator didn't return a valid instance"); } } inUse.Add(instance); } finally { rwlock.ReleaseWriterLock(); } return(instance); }
public object Resolve(CreationContext context, IReleasePolicy releasePolicy) { return(activator.Create(context, null)); }
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; }
public virtual object Resolve() { return(componentActivator.Create()); }