예제 #1
0
파일: Container.cs 프로젝트: virajs/Cronus
        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);
        }
예제 #2
0
파일: Container.cs 프로젝트: virajs/Cronus
 public void Dispose()
 {
     scopedMappings.Clear();
     ScopeHolder.EndScope();
 }