Example #1
0
        public ProviderBase CreateProviderFromFactory <TContract, TFactory>(string concreteIdentifier)
            where TFactory : IFactory <TContract>
        {
            var id = new SingletonId(typeof(TContract), concreteIdentifier);

            return(_factorySingletonProviderCreator.CreateProvider <TContract, TFactory>(id));
        }
Example #2
0
 public SingletonLazyCreatorByInstance(
     SingletonId id, SingletonProviderMap owner, DiContainer container, object instance)
     : base(id, owner)
 {
     Assert.That(instance != null || container.IsValidating);
     _instance = instance;
 }
Example #3
0
        public TypeSingletonProvider CreateProvider(SingletonId singletonId)
        {
            var creator = AddCreator(singletonId);

            return(new TypeSingletonProvider(
                       creator, singletonId, _singletonRegistry));
        }
 public TypeSingletonLazyCreator(
     SingletonId id, TypeSingletonProviderCreator owner,
     DiContainer container)
 {
     _container = container;
     _id        = id;
     _owner     = owner;
 }
 public MethodSingletonLazyCreator(
     SingletonId id, MethodSingletonProviderCreator owner,
     Func <InjectContext, TConcrete> createMethod)
 {
     _owner        = owner;
     _createMethod = createMethod;
     _id           = id;
 }
 public StandardSingletonDeclaration(
     SingletonId id, List <TypeValuePair> args, SingletonTypes type, object singletonSpecificId)
 {
     Id         = id;
     Type       = type;
     SpecificId = singletonSpecificId;
     Arguments  = args;
 }
 public FactorySingletonLazyCreator(
     SingletonId id, DiContainer container,
     FactorySingletonProviderCreator owner)
 {
     _id        = id;
     _container = container;
     _owner     = owner;
 }
        public FactorySingletonProvider CreateProvider <TContract, TFactory>(SingletonId singletonId)
            where TFactory : IFactory <TContract>
        {
            Assert.IsEqual(typeof(TContract), singletonId.ConcreteType);

            var creator = AddCreator <TContract, TFactory>(singletonId);

            return(new FactorySingletonProvider(creator, _singletonRegistry, singletonId));
        }
 public SingletonLazyCreator(
     DiContainer container, SingletonProviderMap owner,
     SingletonId id, Func <InjectContext, object> createMethod)
 {
     _container    = container;
     _owner        = owner;
     _id           = id;
     _createMethod = createMethod;
 }
        public MethodSingletonProvider CreateProvider <TConcrete>(
            string concreteIdentifier, Func <InjectContext, TConcrete> method)
        {
            var singletonId = new SingletonId(typeof(TConcrete), concreteIdentifier);
            var creator     = AddCreator <TConcrete>(singletonId, method);

            return(new MethodSingletonProvider(
                       creator, singletonId, _singletonRegistry));
        }
        public GameObjectSingletonLazyCreator(
            DiContainer container, GameObjectSingletonProviderCreator owner, SingletonId id)
        {
            Assert.That(id.ConcreteType.DerivesFrom <Component>());

            _container = container;
            _owner     = owner;
            _id        = id;
        }
        public InstanceSingletonProvider(
            InstanceSingletonLazyCreator lazyCreator,
            SingletonRegistry singletonRegistry, SingletonId id)
        {
            _singletonRegistry = singletonRegistry;
            _lazyCreator       = lazyCreator;
            _id = id;

            Init();
        }
Example #13
0
 public TypeSingletonProvider(
     TypeSingletonLazyCreator lazyCreator,
     SingletonId id,
     SingletonRegistry singletonRegistry)
 {
     _singletonRegistry = singletonRegistry;
     _id          = id;
     _lazyCreator = lazyCreator;
     Init();
 }
Example #14
0
        public InstanceSingletonLazyCreator(
            SingletonId id, InstanceSingletonProviderCreator owner,
            DiContainer container, object instance)
        {
            Assert.That(instance != null || container.IsValidating);

            _owner    = owner;
            _id       = id;
            _instance = instance;
        }
        public GameObjectSingletonProvider CreateProvider(
            Type concreteType, string concreteIdentifier)
        {
            Assert.That(concreteType.DerivesFrom <Component>());

            var singletonId = new SingletonId(concreteType, concreteIdentifier);
            var creator     = AddCreator(singletonId);

            return(new GameObjectSingletonProvider(creator, singletonId, _singletonRegistry));
        }
        public GameObjectSingletonProvider(
            GameObjectSingletonLazyCreator creator,
            SingletonId id,
            SingletonRegistry singletonRegistry)
        {
            _singletonRegistry = singletonRegistry;
            _id      = id;
            _creator = creator;

            Init();
        }
Example #17
0
        public SingletonTypes?TryGetSingletonType(SingletonId id)
        {
            SingletonTypes type;

            if (_singletonTypes.TryGetValue(id, out type))
            {
                return(type);
            }

            return(null);
        }
Example #18
0
        public FactorySingletonProvider(
            IFactorySingletonLazyCreator lazyCreator,
            SingletonRegistry singletonRegistry,
            SingletonId id)
        {
            _id = id;
            _singletonRegistry = singletonRegistry;
            _lazyCreator       = lazyCreator;

            Init();
        }
Example #19
0
        public SingletonTypes?TryGetSingletonType(SingletonId id)
        {
            SingletonInfo info;

            if (_singletonInfos.TryGetValue(id, out info))
            {
                return(info.Type);
            }

            return(null);
        }
Example #20
0
        public ProviderBase CreateProviderFromType(SingletonId singleId)
        {
            var creator = TryGetCreator <SingletonLazyCreatorByType>(singleId);

            if (creator == null)
            {
                creator = new SingletonLazyCreatorByType(singleId, this, _container);
                _creators.Add(singleId, creator);
            }

            return(CreateProvider(creator));
        }
Example #21
0
        TypeSingletonLazyCreator AddCreator(SingletonId id)
        {
            TypeSingletonLazyCreator creator;

            if (!_creators.TryGetValue(id, out creator))
            {
                creator = new TypeSingletonLazyCreator(id, this, _container);
                _creators.Add(id, creator);
            }

            return(creator);
        }
        GameObjectSingletonLazyCreator AddCreator(SingletonId id)
        {
            GameObjectSingletonLazyCreator creator;

            if (!_creators.TryGetValue(id, out creator))
            {
                creator = new GameObjectSingletonLazyCreator(_container, this, id);
                _creators.Add(id, creator);
            }

            return(creator);
        }
Example #23
0
        public void UnmarkPrefab(SingletonId id, GameObject prefab)
        {
            var markInfo = _prefabMarks[id];

            Assert.IsEqual(markInfo.Prefab, prefab);

            markInfo.RefCount -= 1;

            if (markInfo.RefCount == 0)
            {
                _prefabMarks.RemoveWithConfirm(id);
            }
        }
Example #24
0
        SingletonLazyCreator AddCreator(SingletonId id)
        {
            SingletonLazyCreator creator;

            if (!_creators.TryGetValue(id, out creator))
            {
                creator = new SingletonLazyCreator(_container, this, id);
                _creators.Add(id, creator);
            }

            creator.IncRefCount();
            return(creator);
        }
Example #25
0
        public void UnmarkGameObject(SingletonId id, GameObject gameObject)
        {
            var markInfo = _gameObjectMarks[id];

            Assert.IsEqual(markInfo.GameObject, gameObject);

            markInfo.RefCount -= 1;

            if (markInfo.RefCount == 0)
            {
                _gameObjectMarks.RemoveWithConfirm(id);
            }
        }
Example #26
0
        public void UnmarkResource(SingletonId id, string resourcePath)
        {
            var markInfo = _resourceMarks[id];

            Assert.IsEqual(markInfo.ResourcePath, resourcePath);

            markInfo.RefCount -= 1;

            if (markInfo.RefCount == 0)
            {
                _resourceMarks.RemoveWithConfirm(id);
            }
        }
Example #27
0
        public ProviderBase CreateProviderFromFactory <TContract, TFactory>(string identifier)
            where TFactory : IFactory <TContract>
        {
            var singleId = new SingletonId(identifier, typeof(TContract));
            var creator  = TryGetCreator <SingletonLazyCreatorByFactory <TContract, TFactory> >(singleId);

            if (creator == null)
            {
                creator = new SingletonLazyCreatorByFactory <TContract, TFactory>(singleId, this, _container);
                _creators.Add(singleId, creator);
            }

            return(CreateProvider(creator));
        }
Example #28
0
        public void UnmarkSingleton(SingletonId id, SingletonTypes type)
        {
            Assert.That(_singletonInfos.ContainsKey(id));

            var info = _singletonInfos[id];

            Assert.IsEqual(type, info.Type);

            info.RefCount -= 1;

            if (info.RefCount == 0)
            {
                _singletonInfos.RemoveWithConfirm(id);
            }
        }
        public PrefabResourceSingletonProvider(
            PrefabResourceSingletonId resourceId, Type componentType,
            PrefabResourceSingletonLazyCreator lazyCreator,
            SingletonRegistry singletonRegistry,
            PrefabResourceSingletonProviderCreator owner)
        {
            _owner = owner;
            Assert.That(componentType.DerivesFromOrEqual <Component>());

            _singletonRegistry = singletonRegistry;
            _lazyCreator       = lazyCreator;
            _componentType     = componentType;
            _resourceId        = resourceId;
            _singletonId       = new SingletonId(componentType, resourceId.ConcreteIdentifier);

            Init();
        }
Example #30
0
        public void MarkSingleton(SingletonId id, SingletonTypes type)
        {
            SingletonTypes existingType;

            if (_singletonTypes.TryGetValue(id, out existingType))
            {
                if (existingType != type)
                {
                    throw Assert.CreateException(
                              "Cannot use both '{0}' and '{1}' for the same type/concreteIdentifier!", existingType, type);
                }
            }
            else
            {
                _singletonTypes.Add(id, type);
            }
        }