Beispiel #1
0
        public Context(string name)
        {
            _name = name;
            ContextRegistry.RegisterContext(name, this);
            _dependencies         = new Dictionary <Type, object>();
            _listedDependencies   = new List <object>();
            _factories            = new Dictionary <Type, IFactoryFacade>();
            _autoCompositionTypes = new HashSet <Type>();

            EventManager = new EventManager();
            EventManager.EventInjectors += OnBlindEventHandler;
            RegisterDependency <IEventDispatcher>(EventManager);

            _parentContext = ParentContextStub.STUB;
        }
Beispiel #2
0
        public Context SetParentContext(string parentName)
        {
            if (_name == parentName)
            {
                throw new BehaviourInjectException("Scopes can not be cycled: " + _name + " - " + parentName);
            }

            EventManager.ClearParent();

            Context parentContext = ContextRegistry.GetContext(parentName);

            _parentContext = parentContext;
            EventManager.SetParent(_parentContext.EventManager);

            return(this);
        }
Beispiel #3
0
        //[Obsolete("Use Context.Create() instead")]
        private Context(string name, bool isGlobal = true)
        {
            _name               = name;
            _isGlobal           = isGlobal;
            _dependencies       = new Dictionary <Type, IDependency>(32);
            _listedDependencies = new List <IDependency>(32);

            _commands        = new List <CommandEntry>(32);
            _commandsByEvent = new Dictionary <Type, CommandEntry>(32);

            EventManager = new EventManager();
            EventManager.AddTransmitter(this);
            RegisterDependency <IEventDispatcher>(EventManager);
            RegisterDependency <IInstantiator>(new LocalInstantiator(this));

            _parentContext = ParentContextStub.STUB;
        }
Beispiel #4
0
        public Context SetParentContext(string parentName)
        {
            if (_name == parentName)
            {
                throw new ContextCreationException("Scopes can not be cycled: " + _name + " - " + parentName);
            }

            _parentContext.OnContextDestroyed -= HandleParentDestroyed;

            EventManager.ClearParent();

            Context parentContext = ContextRegistry.GetContext(parentName);

            _parentContext = parentContext;
            _parentContext.OnContextDestroyed += HandleParentDestroyed;
            EventManager.SetParent(_parentContext.EventManager);

            return(this);
        }