public SingletonLazyCreatorByInstance(
     SingletonId id, SingletonProviderMap owner, DiContainer container, object instance)
     : base(id, owner)
 {
     Assert.That(instance != null || container.IsValidating);
     _instance = instance;
 }
 public TypeSingletonLazyCreator(
     SingletonId id, TypeSingletonProviderCreator owner,
     DiContainer container)
 {
     _container = container;
     _id = id;
     _owner = owner;
 }
 public StandardSingletonDeclaration(
     SingletonId id, List<TypeValuePair> args, SingletonTypes type, object singletonSpecificId)
 {
     Id = id;
     Type = type;
     SpecificId = singletonSpecificId;
     Arguments = args;
 }
 public SingletonLazyCreator(
     DiContainer container, SingletonProviderMap owner,
     SingletonId id, Func<InjectContext, object> createMethod = null)
 {
     _container = container;
     _owner = owner;
     _id = id;
     _createMethod = createMethod;
 }
        public GameObjectSingletonLazyCreator(
            DiContainer container, GameObjectSingletonProviderCreator owner, SingletonId id)
        {
            Assert.That(id.ConcreteType.DerivesFrom<Component>());

            _container = container;
            _owner = owner;
            _id = id;
        }
        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);
        }
Esempio n. 7
0
        public InstanceSingletonProvider(
            InstanceSingletonLazyCreator lazyCreator,
            SingletonRegistry singletonRegistry, SingletonId id)
        {
            _singletonRegistry = singletonRegistry;
            _lazyCreator = lazyCreator;
            _id = id;

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

            _owner = owner;
            _id = id;
            _instance = instance;
        }
Esempio n. 10
0
        public GameObjectSingletonProvider(
            GameObjectSingletonLazyCreator creator,
            SingletonId id,
            SingletonRegistry singletonRegistry)
        {
            _singletonRegistry = singletonRegistry;
            _id = id;
            _creator = creator;

            Init();
        }
Esempio n. 11
0
        public FactorySingletonProvider(
            IFactorySingletonLazyCreator lazyCreator,
            SingletonRegistry singletonRegistry,
            SingletonId id)
        {
            _id = id;
            _singletonRegistry = singletonRegistry;
            _lazyCreator = lazyCreator;

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

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

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

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

            return creator;
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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();
        }
        public MonoBehaviourSingletonProvider(
            MonoBehaviourSingletonId monoBehaviourId,
            Type componentType,
            MonoBehaviourSingletonLazyCreator lazyCreator,
            SingletonRegistry singletonRegistry,
            MonoBehaviourSingletonProviderCreator owner)
        {
            _owner = owner;
            Assert.That(componentType.DerivesFromOrEqual<Component>());

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

            Init();
        }
        InstanceSingletonLazyCreator AddCreator(SingletonId id, object instance)
        {
            InstanceSingletonLazyCreator creator;

            if (_creators.TryGetValue(id, out creator))
            {
                if (!ReferenceEquals(instance, creator.Instance))
                {
                    throw new ZenjectBindException(
                        "Cannot use 'ToSingleInstance' with multiple different instances!");
                }
            }
            else
            {
                creator = new InstanceSingletonLazyCreator(
                    id, this, _container, instance);
                _creators.Add(id, creator);
            }

            return creator;
        }
        // Need to do this to ensure that we don't use multiple different ToMonoBehaviour
        // bindings with different game objects but same type/id
        public void MarkGameObject(SingletonId id, GameObject gameObject)
        {
            GameObjectMarkInfo markInfo;

            if (_gameObjectMarks.TryGetValue(id, out markInfo))
            {
                if (markInfo.GameObject != gameObject)
                {
                    throw new ZenjectBindException(
                        "Attempted to use multiple different Game Objects with ToSingleMonoBehaviour using the same type/identifier: '{0}' / '{1}'"
                        .Fmt(id.ConcreteType, id.ConcreteIdentifier));
                }
            }
            else
            {
                markInfo = new GameObjectMarkInfo()
                {
                    GameObject = gameObject,
                };
                _gameObjectMarks.Add(id, markInfo);
            }

            markInfo.RefCount += 1;
        }
        // Need to do this to ensure that we don't use multiple different prefabs
        // with the same singleton ID
        public void MarkPrefab(SingletonId id, GameObject prefab)
        {
            PrefabMarkInfo markInfo;

            if (_prefabMarks.TryGetValue(id, out markInfo))
            {
                if (markInfo.Prefab != prefab)
                {
                    throw new ZenjectBindException(
                        "Attempted to use multiple different prefabs with ToSinglePrefab using the same type/identifier: '{0}' / '{1}'"
                        .Fmt(id.ConcreteType, id.ConcreteIdentifier));
                }
            }
            else
            {
                markInfo = new PrefabMarkInfo()
                {
                    Prefab = prefab,
                };
                _prefabMarks.Add(id, markInfo);
            }

            markInfo.RefCount += 1;
        }
        // Need to do this to ensure that we don't use multiple different prefabs
        // with the same singleton ID
        public void MarkResource(SingletonId id, string resourcePath)
        {
            ResourceMarkInfo markInfo;

            if (_resourceMarks.TryGetValue(id, out markInfo))
            {
                if (markInfo.ResourcePath != resourcePath)
                {
                    throw new ZenjectBindException(
                        "Attempted to use multiple different resource paths with ToSinglePrefabResource using the same type/identifier: '{0}' / '{1}'"
                        .Fmt(id.ConcreteType, id.ConcreteIdentifier));
                }
            }
            else
            {
                markInfo = new ResourceMarkInfo()
                {
                    ResourcePath = resourcePath,
                };
                _resourceMarks.Add(id, markInfo);
            }

            markInfo.RefCount += 1;
        }
Esempio n. 23
0
 public SingletonLazyCreator(
     DiContainer container, SingletonProviderMap owner, SingletonId id)
     : this(container, owner, id, null)
 {
 }
 public SingletonLazyCreatorByType(
     SingletonId id, SingletonProviderMap owner, DiContainer container)
     : base(id, owner)
 {
     _container = container;
 }
 public InstanceSingletonProvider CreateProvider(SingletonId singletonId, object instance)
 {
     var creator = AddCreator(singletonId, instance);
     return new InstanceSingletonProvider(creator, _singletonRegistry, singletonId);
 }
 public void RemoveCreator(SingletonId id)
 {
     bool success = _creators.Remove(id);
     Assert.That(success);
 }
 public TypeSingletonProvider CreateProvider(SingletonId singletonId)
 {
     var creator = AddCreator(singletonId);
     return new TypeSingletonProvider(
         creator, singletonId, _singletonRegistry);
 }
Esempio n. 28
0
        public static ModifiablePropertyType GetProperty(KeyValuePair<string, object> dmsPropertyValue)
		{
			var dmsProperty = default(ModifiablePropertyType);

			if (dmsPropertyValue.Value == null)
			{
				dmsProperty = new SingletonString { Value = null };
			}
			else
			{
				var propertyType = dmsPropertyValue.Value.GetType();

				if (propertyType == typeof(string))
				{
					dmsProperty = new SingletonString
					{
						Value = Convert.ToString(dmsPropertyValue.Value)
					};
				}
				else if (propertyType == typeof(bool) || propertyType == typeof(bool?))
				{
					dmsProperty = new SingletonBoolean
					{
						Value = Convert.ToBoolean(dmsPropertyValue.Value),
						ValueSpecified = true
					};
				}
				else if (propertyType == typeof(int) || propertyType == typeof(int?))
				{
					dmsProperty = new SingletonInteger32
					{
						Value = Convert.ToInt32(dmsPropertyValue.Value),
						ValueSpecified = true
					};
				}
				else if (propertyType == typeof(float) || propertyType == typeof(float?) ||
						 propertyType == typeof(double) || propertyType == typeof(double?))
				{
					dmsProperty = new SingletonFloat64
					{
						Value = Convert.ToDouble(dmsPropertyValue.Value),
						ValueSpecified = true
					};
				}
				else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
				{
					dmsProperty = new SingletonDateTime
					{
						Value = Convert.ToDateTime(dmsPropertyValue.Value),
						ValueSpecified = true
					};
				}
				else if (propertyType == typeof(Guid) || propertyType == typeof(Guid?))
				{
					dmsProperty = new SingletonId
					{
						Value = ((Guid)dmsPropertyValue.Value).ToString()
					};
				}
				else if (propertyType == typeof(string[]))
				{
					dmsProperty = new ListOfString
					{
						Value = (string[])dmsPropertyValue.Value
					};
				}
				else if (propertyType == typeof(List<string>))
				{
					dmsProperty = new ListOfString
					{
						Value = ((List<string>)dmsPropertyValue.Value).ToArray()
					};
				}
				else
				{
					throw new NotImplementedException(propertyType.FullName);
				}
			}
				
			dmsProperty.propertyId = dmsPropertyValue.Key;

			return dmsProperty;
		}
Esempio n. 29
0
 public SingletonLazyCreatorBase(
     SingletonId id, SingletonProviderMap owner)
 {
     _id = id;
     _owner = owner;
 }