コード例 #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));
        }
コード例 #2
0
 public SingletonLazyCreatorByInstance(
     SingletonId id, SingletonProviderMap owner, DiContainer container, object instance)
     : base(id, owner)
 {
     Assert.That(instance != null || container.IsValidating);
     _instance = instance;
 }
コード例 #3
0
        public TypeSingletonProvider CreateProvider(SingletonId singletonId)
        {
            var creator = AddCreator(singletonId);

            return(new TypeSingletonProvider(
                       creator, singletonId, _singletonRegistry));
        }
コード例 #4
0
 public TypeSingletonLazyCreator(
     SingletonId id, TypeSingletonProviderCreator owner,
     DiContainer container)
 {
     _container = container;
     _id        = id;
     _owner     = owner;
 }
コード例 #5
0
 public MethodSingletonLazyCreator(
     SingletonId id, MethodSingletonProviderCreator owner,
     Func <InjectContext, TConcrete> createMethod)
 {
     _owner        = owner;
     _createMethod = createMethod;
     _id           = id;
 }
コード例 #6
0
 public StandardSingletonDeclaration(
     SingletonId id, List <TypeValuePair> args, SingletonTypes type, object singletonSpecificId)
 {
     Id         = id;
     Type       = type;
     SpecificId = singletonSpecificId;
     Arguments  = args;
 }
コード例 #7
0
 public FactorySingletonLazyCreator(
     SingletonId id, DiContainer container,
     FactorySingletonProviderCreator owner)
 {
     _id        = id;
     _container = container;
     _owner     = owner;
 }
コード例 #8
0
        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));
        }
コード例 #9
0
 public SingletonLazyCreator(
     DiContainer container, SingletonProviderMap owner,
     SingletonId id, Func <InjectContext, object> createMethod)
 {
     _container    = container;
     _owner        = owner;
     _id           = id;
     _createMethod = createMethod;
 }
コード例 #10
0
        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));
        }
コード例 #11
0
        public GameObjectSingletonLazyCreator(
            DiContainer container, GameObjectSingletonProviderCreator owner, SingletonId id)
        {
            Assert.That(id.ConcreteType.DerivesFrom <Component>());

            _container = container;
            _owner     = owner;
            _id        = id;
        }
コード例 #12
0
        public InstanceSingletonProvider(
            InstanceSingletonLazyCreator lazyCreator,
            SingletonRegistry singletonRegistry, SingletonId id)
        {
            _singletonRegistry = singletonRegistry;
            _lazyCreator       = lazyCreator;
            _id = id;

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

            _owner    = owner;
            _id       = id;
            _instance = instance;
        }
コード例 #15
0
        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));
        }
コード例 #16
0
        public GameObjectSingletonProvider(
            GameObjectSingletonLazyCreator creator,
            SingletonId id,
            SingletonRegistry singletonRegistry)
        {
            _singletonRegistry = singletonRegistry;
            _id      = id;
            _creator = creator;

            Init();
        }
コード例 #17
0
        public SingletonTypes?TryGetSingletonType(SingletonId id)
        {
            SingletonTypes type;

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

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

            Init();
        }
コード例 #19
0
        public SingletonTypes?TryGetSingletonType(SingletonId id)
        {
            SingletonInfo info;

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

            return(null);
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #22
0
        GameObjectSingletonLazyCreator AddCreator(SingletonId id)
        {
            GameObjectSingletonLazyCreator creator;

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

            return(creator);
        }
コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #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));
        }
コード例 #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);
            }
        }
コード例 #29
0
        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();
        }
コード例 #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);
            }
        }