internal object GetInstance(MappingKey key) { Lazy <object> createScopedInstance; if (scopedMappings.TryGetValue(key, out createScopedInstance)) { return(createScopedInstance.Value); } else { if (String.IsNullOrEmpty(key.InstanceName)) { var scopedKey = new MappingKey(key.Type, Scope.GetCurrentScope().ScopeType); if (scopedMappings.TryGetValue(scopedKey, out createScopedInstance)) { return(createScopedInstance.Value); } else { // If we do cannot create an instance there is a possibility the requested key to be registered in a parent scope. // If that is the case the instance is created within the correct scope without switching the current scope. Scope scopeContainingMappingKey; MappingKey keyToResolveFromFoundScope; if (ScopeHolder.TryFindWithinParents(scopedKey, ScopeHolder.CurrentScope, out scopeContainingMappingKey, out keyToResolveFromFoundScope)) { return(scopeContainingMappingKey.GetInstance(keyToResolveFromFoundScope)); } } } } return(null); }
public void Dispose() { scopedMappings.Clear(); ScopeHolder.EndScope(); }