Initial Commit
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class CachedOpenTypeProvider : IProvider
|
||||
{
|
||||
readonly IProvider _creator;
|
||||
readonly List<List<object>> _cachedInstances = new List<List<object>>();
|
||||
|
||||
#if ZEN_MULTITHREADING
|
||||
readonly object _locker = new object();
|
||||
#else
|
||||
bool _isCreatingInstance;
|
||||
#endif
|
||||
|
||||
public CachedOpenTypeProvider(IProvider creator)
|
||||
{
|
||||
Assert.That(creator.TypeVariesBasedOnMemberType);
|
||||
_creator = creator;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get
|
||||
{
|
||||
// Should not call this
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
|
||||
public int NumInstances
|
||||
{
|
||||
get
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
return _cachedInstances.Select(x => x.Count).Sum();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This method can be called if you want to clear the memory for an AsSingle instance,
|
||||
// See isssue https://github.com/svermeulen/Zenject/issues/441
|
||||
public void ClearCache()
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
_cachedInstances.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _creator.GetInstanceType(context);
|
||||
}
|
||||
|
||||
List<object> TryGetMatchFromCache(Type memberType)
|
||||
{
|
||||
List<object> result = null;
|
||||
|
||||
for (int i = 0; i < _cachedInstances.Count; i++)
|
||||
{
|
||||
var instanceList = _cachedInstances[i];
|
||||
|
||||
bool matchesAll = true;
|
||||
|
||||
for (int k = 0; k < instanceList.Count; k++)
|
||||
{
|
||||
var instance = instanceList[k];
|
||||
|
||||
if (instance == null)
|
||||
{
|
||||
if (memberType.IsValueType())
|
||||
{
|
||||
matchesAll = false;
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!instance.GetType().DerivesFromOrEqual(memberType))
|
||||
{
|
||||
matchesAll = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchesAll)
|
||||
{
|
||||
Assert.IsNull(result); // Is there any case where this is hit?
|
||||
result = instanceList;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var instances = TryGetMatchFromCache(context.MemberType);
|
||||
|
||||
if (instances != null)
|
||||
{
|
||||
injectAction = null;
|
||||
buffer.AllocFreeAddRange(instances);
|
||||
return;
|
||||
}
|
||||
|
||||
#if !ZEN_MULTITHREADING
|
||||
// This should only happen with constructor injection
|
||||
// Field or property injection should allow circular dependencies
|
||||
if (_isCreatingInstance)
|
||||
{
|
||||
var instanceType = _creator.GetInstanceType(context);
|
||||
throw Assert.CreateException(
|
||||
"Found circular dependency when creating type '{0}'. Object graph:\n {1}{2}\n",
|
||||
instanceType, context.GetObjectGraphString(), instanceType);
|
||||
}
|
||||
|
||||
_isCreatingInstance = true;
|
||||
#endif
|
||||
|
||||
instances = new List<object>();
|
||||
_creator.GetAllInstancesWithInjectSplit(
|
||||
context, args, out injectAction, instances);
|
||||
Assert.IsNotNull(instances);
|
||||
|
||||
_cachedInstances.Add(instances);
|
||||
#if !ZEN_MULTITHREADING
|
||||
_isCreatingInstance = false;
|
||||
#endif
|
||||
buffer.AllocFreeAddRange(instances);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a09a4770eaace44a84d9d627f0bd161
|
||||
timeCreated: 1528211680
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class CachedProvider : IProvider
|
||||
{
|
||||
readonly IProvider _creator;
|
||||
|
||||
List<object> _instances;
|
||||
|
||||
#if ZEN_MULTITHREADING
|
||||
readonly object _locker = new object();
|
||||
#else
|
||||
bool _isCreatingInstance;
|
||||
#endif
|
||||
|
||||
public CachedProvider(IProvider creator)
|
||||
{
|
||||
_creator = creator;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get
|
||||
{
|
||||
// Should not call this
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
|
||||
public int NumInstances
|
||||
{
|
||||
get
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
return _instances == null ? 0 : _instances.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This method can be called if you want to clear the memory for an AsSingle instance,
|
||||
// See isssue https://github.com/svermeulen/Zenject/issues/441
|
||||
public void ClearCache()
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
_instances = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _creator.GetInstanceType(context);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
if (_instances != null)
|
||||
{
|
||||
injectAction = null;
|
||||
buffer.AllocFreeAddRange(_instances);
|
||||
return;
|
||||
}
|
||||
|
||||
#if !ZEN_MULTITHREADING
|
||||
// This should only happen with constructor injection
|
||||
// Field or property injection should allow circular dependencies
|
||||
if (_isCreatingInstance)
|
||||
{
|
||||
var instanceType = _creator.GetInstanceType(context);
|
||||
throw Assert.CreateException(
|
||||
"Found circular dependency when creating type '{0}'. Object graph:\n {1}{2}\n",
|
||||
instanceType, context.GetObjectGraphString(), instanceType);
|
||||
}
|
||||
|
||||
_isCreatingInstance = true;
|
||||
#endif
|
||||
|
||||
var instances = new List<object>();
|
||||
_creator.GetAllInstancesWithInjectSplit(context, args, out injectAction, instances);
|
||||
Assert.IsNotNull(instances);
|
||||
|
||||
_instances = instances;
|
||||
#if !ZEN_MULTITHREADING
|
||||
_isCreatingInstance = false;
|
||||
#endif
|
||||
buffer.AllocFreeAddRange(instances);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6e16beb21a2f0d4db901700c6ed3099
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d80a7db637267834388a31f2b7ddcf36
|
||||
folderAsset: yes
|
||||
timeCreated: 1461708046
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a0ec9eb479742940a10701ec8a1d087
|
||||
folderAsset: yes
|
||||
timeCreated: 1461708047
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class AddToCurrentGameObjectComponentProvider : IProvider
|
||||
{
|
||||
readonly Type _componentType;
|
||||
readonly DiContainer _container;
|
||||
readonly List<TypeValuePair> _extraArguments;
|
||||
readonly object _concreteIdentifier;
|
||||
readonly Action<InjectContext, object> _instantiateCallback;
|
||||
|
||||
public AddToCurrentGameObjectComponentProvider(
|
||||
DiContainer container, Type componentType,
|
||||
IEnumerable<TypeValuePair> extraArguments, object concreteIdentifier,
|
||||
Action<InjectContext, object> instantiateCallback)
|
||||
{
|
||||
Assert.That(componentType.DerivesFrom<Component>());
|
||||
|
||||
_extraArguments = extraArguments.ToList();
|
||||
_componentType = componentType;
|
||||
_container = container;
|
||||
_concreteIdentifier = concreteIdentifier;
|
||||
_instantiateCallback = instantiateCallback;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
protected DiContainer Container
|
||||
{
|
||||
get { return _container; }
|
||||
}
|
||||
|
||||
protected Type ComponentType
|
||||
{
|
||||
get { return _componentType; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _componentType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(context.ObjectType.DerivesFrom<Component>(),
|
||||
"Object '{0}' can only be injected into MonoBehaviour's since it was bound with 'FromNewComponentSibling'. Attempted to inject into non-MonoBehaviour '{1}'",
|
||||
context.MemberType, context.ObjectType);
|
||||
|
||||
object instance;
|
||||
|
||||
if (!_container.IsValidating || TypeAnalyzer.ShouldAllowDuringValidation(_componentType))
|
||||
{
|
||||
var gameObj = ((Component)context.ObjectInstance).gameObject;
|
||||
|
||||
var componentInstance = gameObj.GetComponent(_componentType);
|
||||
instance = componentInstance;
|
||||
|
||||
// Use componentInstance so that it triggers unity's overloaded comparison operator
|
||||
// So if the component is there but missing then it returns null
|
||||
// (https://github.com/svermeulen/Zenject/issues/582)
|
||||
if (componentInstance != null)
|
||||
{
|
||||
injectAction = null;
|
||||
buffer.Add(instance);
|
||||
return;
|
||||
}
|
||||
|
||||
instance = gameObj.AddComponent(_componentType);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = new ValidationMarker(_componentType);
|
||||
}
|
||||
|
||||
// Note that we don't just use InstantiateComponentOnNewGameObjectExplicit here
|
||||
// because then circular references don't work
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
|
||||
|
||||
extraArgs.AllocFreeAddRange(_extraArguments);
|
||||
extraArgs.AllocFreeAddRange(args);
|
||||
|
||||
_container.InjectExplicit(instance, _componentType, extraArgs, context, _concreteIdentifier);
|
||||
|
||||
Assert.That(extraArgs.IsEmpty());
|
||||
ZenPools.DespawnList(extraArgs);
|
||||
|
||||
if (_instantiateCallback != null)
|
||||
{
|
||||
_instantiateCallback(context, instance);
|
||||
}
|
||||
};
|
||||
|
||||
buffer.Add(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b0521d85aeb9ee479dcb29ef4d88547
|
||||
timeCreated: 1465651364
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class AddToExistingGameObjectComponentProvider : AddToGameObjectComponentProviderBase
|
||||
{
|
||||
readonly GameObject _gameObject;
|
||||
|
||||
public AddToExistingGameObjectComponentProvider(
|
||||
GameObject gameObject, DiContainer container, Type componentType,
|
||||
IEnumerable<TypeValuePair> extraArguments, object concreteIdentifier,
|
||||
Action<InjectContext, object> instantiateCallback)
|
||||
: base(container, componentType, extraArguments, concreteIdentifier, instantiateCallback)
|
||||
{
|
||||
_gameObject = gameObject;
|
||||
}
|
||||
|
||||
// This will cause [Inject] to be triggered after awake / start
|
||||
// We could return true, but what if toggling active has other negative repercussions?
|
||||
// For now let's just not do anything
|
||||
protected override bool ShouldToggleActive
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
protected override GameObject GetGameObject(InjectContext context)
|
||||
{
|
||||
return _gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class AddToExistingGameObjectComponentProviderGetter : AddToGameObjectComponentProviderBase
|
||||
{
|
||||
readonly Func<InjectContext, GameObject> _gameObjectGetter;
|
||||
|
||||
public AddToExistingGameObjectComponentProviderGetter(
|
||||
Func<InjectContext, GameObject> gameObjectGetter, DiContainer container, Type componentType,
|
||||
List<TypeValuePair> extraArguments, object concreteIdentifier,
|
||||
Action<InjectContext, object> instantiateCallback)
|
||||
: base(container, componentType, extraArguments, concreteIdentifier, instantiateCallback)
|
||||
{
|
||||
_gameObjectGetter = gameObjectGetter;
|
||||
}
|
||||
|
||||
// This will cause [Inject] to be triggered after awake / start
|
||||
// We could return true, but what if toggling active has other negative repercussions?
|
||||
// For now let's just not do anything
|
||||
protected override bool ShouldToggleActive
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
protected override GameObject GetGameObject(InjectContext context)
|
||||
{
|
||||
var gameObj = _gameObjectGetter(context);
|
||||
Assert.IsNotNull(gameObj, "Provided Func<InjectContext, GameObject> returned null value for game object when using FromComponentOn");
|
||||
return gameObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 669e8af5b17774d45acea73d348e6dca
|
||||
timeCreated: 1461708051
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public abstract class AddToGameObjectComponentProviderBase : IProvider
|
||||
{
|
||||
readonly Type _componentType;
|
||||
readonly DiContainer _container;
|
||||
readonly List<TypeValuePair> _extraArguments;
|
||||
readonly object _concreteIdentifier;
|
||||
readonly Action<InjectContext, object> _instantiateCallback;
|
||||
|
||||
public AddToGameObjectComponentProviderBase(
|
||||
DiContainer container, Type componentType,
|
||||
IEnumerable<TypeValuePair> extraArguments, object concreteIdentifier,
|
||||
Action<InjectContext, object> instantiateCallback)
|
||||
{
|
||||
Assert.That(componentType.DerivesFrom<Component>());
|
||||
|
||||
_extraArguments = extraArguments.ToList();
|
||||
_componentType = componentType;
|
||||
_container = container;
|
||||
_concreteIdentifier = concreteIdentifier;
|
||||
_instantiateCallback = instantiateCallback;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
protected DiContainer Container
|
||||
{
|
||||
get { return _container; }
|
||||
}
|
||||
|
||||
protected Type ComponentType
|
||||
{
|
||||
get { return _componentType; }
|
||||
}
|
||||
|
||||
protected abstract bool ShouldToggleActive
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _componentType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
object instance;
|
||||
|
||||
// We still want to make sure we can get the game object during validation
|
||||
var gameObj = GetGameObject(context);
|
||||
|
||||
var wasActive = gameObj.activeSelf;
|
||||
|
||||
if (wasActive && ShouldToggleActive)
|
||||
{
|
||||
// We need to do this in some cases to ensure that [Inject] always gets
|
||||
// called before awake / start
|
||||
gameObj.SetActive(false);
|
||||
}
|
||||
|
||||
if (!_container.IsValidating || TypeAnalyzer.ShouldAllowDuringValidation(_componentType))
|
||||
{
|
||||
if (_componentType == typeof(Transform))
|
||||
// Treat transform as a special case because it's the one component that's always automatically added
|
||||
// Otherwise, calling AddComponent below will fail and return null
|
||||
// This is nice to allow doing things like
|
||||
// Container.Bind<Transform>().FromNewComponentOnNewGameObject();
|
||||
{
|
||||
instance = gameObj.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = gameObj.AddComponent(_componentType);
|
||||
}
|
||||
|
||||
Assert.IsNotNull(instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = new ValidationMarker(_componentType);
|
||||
}
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
|
||||
|
||||
extraArgs.AllocFreeAddRange(_extraArguments);
|
||||
extraArgs.AllocFreeAddRange(args);
|
||||
|
||||
_container.InjectExplicit(instance, _componentType, extraArgs, context, _concreteIdentifier);
|
||||
|
||||
Assert.That(extraArgs.Count == 0);
|
||||
|
||||
ZenPools.DespawnList(extraArgs);
|
||||
|
||||
if (_instantiateCallback != null)
|
||||
{
|
||||
_instantiateCallback(context, instance);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (wasActive && ShouldToggleActive)
|
||||
{
|
||||
gameObj.SetActive(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
buffer.Add(instance);
|
||||
}
|
||||
|
||||
protected abstract GameObject GetGameObject(InjectContext context);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d818f8110e5b31d4eb27001e5c5b3eb9
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class AddToNewGameObjectComponentProvider : AddToGameObjectComponentProviderBase
|
||||
{
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
|
||||
public AddToNewGameObjectComponentProvider(
|
||||
DiContainer container, Type componentType,
|
||||
IEnumerable<TypeValuePair> extraArguments, GameObjectCreationParameters gameObjectBindInfo,
|
||||
object concreteIdentifier,
|
||||
Action<InjectContext, object> instantiateCallback)
|
||||
: base(container, componentType, extraArguments, concreteIdentifier, instantiateCallback)
|
||||
{
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
}
|
||||
|
||||
protected override bool ShouldToggleActive
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
protected override GameObject GetGameObject(InjectContext context)
|
||||
{
|
||||
if (_gameObjectBindInfo.Name == null)
|
||||
{
|
||||
_gameObjectBindInfo.Name = ComponentType.Name;
|
||||
}
|
||||
|
||||
return Container.CreateEmptyGameObject(_gameObjectBindInfo, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e1085d337c03dd42a1d5493c11d9d23
|
||||
timeCreated: 1461708051
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class GetFromGameObjectComponentProvider : IProvider
|
||||
{
|
||||
readonly GameObject _gameObject;
|
||||
readonly Type _componentType;
|
||||
readonly bool _matchSingle;
|
||||
|
||||
// if concreteType is null we use the contract type from inject context
|
||||
public GetFromGameObjectComponentProvider(
|
||||
Type componentType, GameObject gameObject, bool matchSingle)
|
||||
{
|
||||
_componentType = componentType;
|
||||
_matchSingle = matchSingle;
|
||||
_gameObject = gameObject;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _componentType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_matchSingle)
|
||||
{
|
||||
var match = _gameObject.GetComponent(_componentType);
|
||||
|
||||
Assert.IsNotNull(match, "Could not find component with type '{0}' on prefab '{1}'",
|
||||
_componentType, _gameObject.name);
|
||||
|
||||
buffer.Add(match);
|
||||
return;
|
||||
}
|
||||
|
||||
var allComponents = _gameObject.GetComponents(_componentType);
|
||||
|
||||
Assert.That(allComponents.Length >= 1,
|
||||
"Expected to find at least one component with type '{0}' on prefab '{1}'",
|
||||
_componentType, _gameObject.name);
|
||||
|
||||
buffer.AllocFreeAddRange(allComponents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d5cdba9f2e79364dbf4f3d242fd22da
|
||||
timeCreated: 1529229722
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class GetFromGameObjectGetterComponentProvider : IProvider
|
||||
{
|
||||
readonly Func<InjectContext, GameObject> _gameObjectGetter;
|
||||
readonly Type _componentType;
|
||||
readonly bool _matchSingle;
|
||||
|
||||
// if concreteType is null we use the contract type from inject context
|
||||
public GetFromGameObjectGetterComponentProvider(
|
||||
Type componentType, Func<InjectContext, GameObject> gameObjectGetter, bool matchSingle)
|
||||
{
|
||||
_componentType = componentType;
|
||||
_matchSingle = matchSingle;
|
||||
_gameObjectGetter = gameObjectGetter;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _componentType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
buffer.Add(new ValidationMarker(_componentType));
|
||||
}
|
||||
else
|
||||
{
|
||||
var gameObject = _gameObjectGetter(context);
|
||||
|
||||
if (_matchSingle)
|
||||
{
|
||||
var match = gameObject.GetComponent(_componentType);
|
||||
|
||||
Assert.IsNotNull(match, "Could not find component with type '{0}' on game object '{1}'",
|
||||
_componentType, gameObject.name);
|
||||
|
||||
buffer.Add(match);
|
||||
return;
|
||||
}
|
||||
|
||||
var allComponents = gameObject.GetComponents(_componentType);
|
||||
|
||||
Assert.That(allComponents.Length >= 1,
|
||||
"Expected to find at least one component with type '{0}' on prefab '{1}'",
|
||||
_componentType, gameObject.name);
|
||||
|
||||
buffer.AllocFreeAddRange(allComponents);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 766643a5935eb704a929da28681bf70e
|
||||
timeCreated: 1529230207
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class GetFromPrefabComponentProvider : IProvider
|
||||
{
|
||||
readonly IPrefabInstantiator _prefabInstantiator;
|
||||
readonly Type _componentType;
|
||||
readonly bool _matchSingle;
|
||||
|
||||
// if concreteType is null we use the contract type from inject context
|
||||
public GetFromPrefabComponentProvider(
|
||||
Type componentType,
|
||||
IPrefabInstantiator prefabInstantiator, bool matchSingle)
|
||||
{
|
||||
_prefabInstantiator = prefabInstantiator;
|
||||
_componentType = componentType;
|
||||
_matchSingle = matchSingle;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _componentType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
var gameObject = _prefabInstantiator.Instantiate(context, args, out injectAction);
|
||||
|
||||
// NOTE: Need to set includeInactive to true here, because prefabs are always
|
||||
// instantiated as disabled until injection occurs, so that Awake / OnEnabled is executed
|
||||
// after injection has occurred
|
||||
|
||||
if (_matchSingle)
|
||||
{
|
||||
var match = gameObject.GetComponentInChildren(_componentType, true);
|
||||
|
||||
Assert.IsNotNull(match, "Could not find component with type '{0}' on prefab '{1}'",
|
||||
_componentType, _prefabInstantiator.GetPrefab(context).name);
|
||||
|
||||
buffer.Add(match);
|
||||
return;
|
||||
}
|
||||
|
||||
var allComponents = gameObject.GetComponentsInChildren(_componentType, true);
|
||||
|
||||
Assert.That(allComponents.Length >= 1,
|
||||
"Expected to find at least one component with type '{0}' on prefab '{1}'",
|
||||
_componentType, _prefabInstantiator.GetPrefab(context).name);
|
||||
|
||||
buffer.AllocFreeAddRange(allComponents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6a49432e004bd8409d3ddea6a45a3f8
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class InstantiateOnPrefabComponentProvider : IProvider
|
||||
{
|
||||
readonly IPrefabInstantiator _prefabInstantiator;
|
||||
readonly Type _componentType;
|
||||
|
||||
// if concreteType is null we use the contract type from inject context
|
||||
public InstantiateOnPrefabComponentProvider(
|
||||
Type componentType,
|
||||
IPrefabInstantiator prefabInstantiator)
|
||||
{
|
||||
_prefabInstantiator = prefabInstantiator;
|
||||
_componentType = componentType;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _componentType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
var gameObject = _prefabInstantiator.Instantiate(context, args, out injectAction);
|
||||
|
||||
var component = gameObject.AddComponent(_componentType);
|
||||
|
||||
buffer.Add(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6836adf19243a045ba39e67ade6dd59
|
||||
timeCreated: 1505729206
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88c8658f07bf600408a596245682c306
|
||||
folderAsset: yes
|
||||
timeCreated: 1528368268
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject.Internal
|
||||
{
|
||||
public interface IDecoratorProvider
|
||||
{
|
||||
void GetAllInstances(
|
||||
IProvider provider, InjectContext context, List<object> buffer);
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class DecoratorProvider<TContract> : IDecoratorProvider
|
||||
{
|
||||
readonly Dictionary<IProvider, List<object>> _cachedInstances =
|
||||
new Dictionary<IProvider, List<object>>();
|
||||
|
||||
readonly DiContainer _container;
|
||||
readonly List<Guid> _factoryBindIds = new List<Guid>();
|
||||
|
||||
List<IFactory<TContract, TContract>> _decoratorFactories;
|
||||
|
||||
#if ZEN_MULTITHREADING
|
||||
readonly object _locker = new object();
|
||||
#endif
|
||||
|
||||
public DecoratorProvider(DiContainer container)
|
||||
{
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public void AddFactoryId(Guid factoryBindId)
|
||||
{
|
||||
_factoryBindIds.Add(factoryBindId);
|
||||
}
|
||||
|
||||
void LazyInitializeDecoratorFactories()
|
||||
{
|
||||
if (_decoratorFactories == null)
|
||||
{
|
||||
_decoratorFactories = new List<IFactory<TContract, TContract>>();
|
||||
|
||||
for (int i = 0; i < _factoryBindIds.Count; i++)
|
||||
{
|
||||
var bindId = _factoryBindIds[i];
|
||||
var factory = _container.ResolveId<IFactory<TContract, TContract>>(bindId);
|
||||
_decoratorFactories.Add(factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GetAllInstances(
|
||||
IProvider provider, InjectContext context, List<object> buffer)
|
||||
{
|
||||
if (provider.IsCached)
|
||||
{
|
||||
List<object> instances;
|
||||
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
if (!_cachedInstances.TryGetValue(provider, out instances))
|
||||
{
|
||||
instances = new List<object>();
|
||||
WrapProviderInstances(provider, context, instances);
|
||||
_cachedInstances.Add(provider, instances);
|
||||
}
|
||||
}
|
||||
|
||||
buffer.AllocFreeAddRange(instances);
|
||||
}
|
||||
else
|
||||
{
|
||||
WrapProviderInstances(provider, context, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void WrapProviderInstances(IProvider provider, InjectContext context, List<object> buffer)
|
||||
{
|
||||
LazyInitializeDecoratorFactories();
|
||||
|
||||
provider.GetAllInstances(context, buffer);
|
||||
|
||||
for (int i = 0; i < buffer.Count; i++)
|
||||
{
|
||||
buffer[i] = DecorateInstance(buffer[i], context);
|
||||
}
|
||||
}
|
||||
|
||||
object DecorateInstance(object instance, InjectContext context)
|
||||
{
|
||||
for (int i = 0; i < _decoratorFactories.Count; i++)
|
||||
{
|
||||
instance = _decoratorFactories[i].Create(
|
||||
context.Container.IsValidating ? default(TContract) : (TContract)instance);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a9aaabef2c47874a8b557ade27987eb
|
||||
timeCreated: 1528368269
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c4a4be4639cdfc4c8d00456887fefb6
|
||||
folderAsset: yes
|
||||
timeCreated: 1461708046
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class EmptyGameObjectProvider : IProvider
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
|
||||
public EmptyGameObjectProvider(
|
||||
DiContainer container, GameObjectCreationParameters gameObjectBindInfo)
|
||||
{
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(GameObject);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
|
||||
injectAction = null;
|
||||
|
||||
var gameObj = _container.CreateEmptyGameObject(_gameObjectBindInfo, context);
|
||||
buffer.Add(gameObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8f4db421196f5849b2139200fdea1a3
|
||||
timeCreated: 1461708055
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PrefabGameObjectProvider : IProvider
|
||||
{
|
||||
readonly IPrefabInstantiator _prefabCreator;
|
||||
|
||||
public PrefabGameObjectProvider(
|
||||
IPrefabInstantiator prefabCreator)
|
||||
{
|
||||
_prefabCreator = prefabCreator;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(GameObject);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
var instance = _prefabCreator.Instantiate(context, args, out injectAction);
|
||||
|
||||
buffer.Add(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d776b7406750d7f4c816cd0c03e4e254
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class GetterProvider<TObj, TResult> : IProvider
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly object _identifier;
|
||||
readonly Func<TObj, TResult> _method;
|
||||
readonly bool _matchAll;
|
||||
readonly InjectSources _sourceType;
|
||||
|
||||
public GetterProvider(
|
||||
object identifier, Func<TObj, TResult> method,
|
||||
DiContainer container, InjectSources sourceType, bool matchAll)
|
||||
{
|
||||
_container = container;
|
||||
_identifier = identifier;
|
||||
_method = method;
|
||||
_matchAll = matchAll;
|
||||
_sourceType = sourceType;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TResult);
|
||||
}
|
||||
|
||||
InjectContext GetSubContext(InjectContext parent)
|
||||
{
|
||||
var subContext = parent.CreateSubContext(
|
||||
typeof(TObj), _identifier);
|
||||
|
||||
subContext.Optional = false;
|
||||
subContext.SourceType = _sourceType;
|
||||
|
||||
return subContext;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TResult).DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_container.IsValidating)
|
||||
{
|
||||
// All we can do is validate that the getter object can be resolved
|
||||
if (_matchAll)
|
||||
{
|
||||
_container.ResolveAll(GetSubContext(context));
|
||||
}
|
||||
else
|
||||
{
|
||||
_container.Resolve(GetSubContext(context));
|
||||
}
|
||||
|
||||
buffer.Add(new ValidationMarker(typeof(TResult)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_matchAll)
|
||||
{
|
||||
Assert.That(buffer.Count == 0);
|
||||
_container.ResolveAll(GetSubContext(context), buffer);
|
||||
|
||||
for (int i = 0; i < buffer.Count; i++)
|
||||
{
|
||||
buffer[i] = _method((TObj)buffer[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(_method(
|
||||
(TObj)_container.Resolve(GetSubContext(context))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce3e2ecdd52e4db469d9bc497ff5e5f5
|
||||
timeCreated: 1461708053
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,396 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public abstract class IFactoryProviderBase<TContract> : IProvider
|
||||
{
|
||||
public IFactoryProviderBase(
|
||||
DiContainer container, Guid factoryId)
|
||||
{
|
||||
Container = container;
|
||||
FactoryId = factoryId;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
protected Guid FactoryId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
protected DiContainer Container
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TContract);
|
||||
}
|
||||
|
||||
public abstract void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer);
|
||||
}
|
||||
|
||||
// Zero parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class IFactoryProvider<TContract> : IFactoryProviderBase<TContract>
|
||||
{
|
||||
public IFactoryProvider(
|
||||
DiContainer container, Guid factoryId)
|
||||
: base(container, factoryId)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.That(args.IsEmpty());
|
||||
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
// Do this even when validating in case it has its own dependencies
|
||||
var factory = Container.ResolveId(typeof(IFactory<TContract>), FactoryId);
|
||||
|
||||
injectAction = null;
|
||||
if (Container.IsValidating)
|
||||
{
|
||||
// We assume here that we are creating a user-defined factory so there's
|
||||
// nothing else we can validate here
|
||||
buffer.Add(new ValidationMarker(typeof(TContract)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(((IFactory<TContract>)factory).Create());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One parameter
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class IFactoryProvider<TParam1, TContract> : IFactoryProviderBase<TContract>
|
||||
{
|
||||
public IFactoryProvider(DiContainer container, Guid factoryId)
|
||||
: base(container, factoryId)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 1);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
|
||||
// Do this even when validating in case it has its own dependencies
|
||||
var factory = Container.ResolveId(typeof(IFactory<TParam1, TContract>), FactoryId);
|
||||
|
||||
injectAction = null;
|
||||
if (Container.IsValidating)
|
||||
{
|
||||
// We assume here that we are creating a user-defined factory so there's
|
||||
// nothing else we can validate here
|
||||
|
||||
buffer.Add(new ValidationMarker(typeof(TContract)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(((IFactory<TParam1, TContract>)factory).Create((TParam1)args[0].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class IFactoryProvider<TParam1, TParam2, TContract> : IFactoryProviderBase<TContract>
|
||||
{
|
||||
public IFactoryProvider(DiContainer container, Guid factoryId)
|
||||
: base(container, factoryId)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 2);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
|
||||
// Do this even when validating in case it has its own dependencies
|
||||
var factory = Container.ResolveId(typeof(IFactory<TParam1, TParam2, TContract>), FactoryId);
|
||||
|
||||
injectAction = null;
|
||||
if (Container.IsValidating)
|
||||
{
|
||||
// We assume here that we are creating a user-defined factory so there's
|
||||
// nothing else we can validate here
|
||||
buffer.Add(new ValidationMarker(typeof(TContract)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
((IFactory<TParam1, TParam2, TContract>)factory).Create(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Three parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class IFactoryProvider<TParam1, TParam2, TParam3, TContract> : IFactoryProviderBase<TContract>
|
||||
{
|
||||
public IFactoryProvider(DiContainer container, Guid factoryId)
|
||||
: base(container, factoryId)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 3);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
|
||||
// Do this even when validating in case it has its own dependencies
|
||||
var factory = Container.ResolveId(typeof(IFactory<TParam1, TParam2, TParam3, TContract>), FactoryId);
|
||||
|
||||
injectAction = null;
|
||||
if (Container.IsValidating)
|
||||
{
|
||||
// We assume here that we are creating a user-defined factory so there's
|
||||
// nothing else we can validate here
|
||||
buffer.Add(new ValidationMarker(typeof(TContract)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
((IFactory<TParam1, TParam2, TParam3, TContract>)factory).Create(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Four parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class IFactoryProvider<TParam1, TParam2, TParam3, TParam4, TContract> : IFactoryProviderBase<TContract>
|
||||
{
|
||||
public IFactoryProvider(DiContainer container, Guid factoryId)
|
||||
: base(container, factoryId)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 4);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
|
||||
// Do this even when validating in case it has its own dependencies
|
||||
var factory = Container.ResolveId(typeof(IFactory<TParam1, TParam2, TParam3, TParam4, TContract>), FactoryId);
|
||||
|
||||
injectAction = null;
|
||||
if (Container.IsValidating)
|
||||
{
|
||||
// We assume here that we are creating a user-defined factory so there's
|
||||
// nothing else we can validate here
|
||||
buffer.Add(new ValidationMarker(typeof(TContract)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
((IFactory<TParam1, TParam2, TParam3, TParam4, TContract>)factory).Create(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Five parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class IFactoryProvider<TParam1, TParam2, TParam3, TParam4, TParam5, TContract> : IFactoryProviderBase<TContract>
|
||||
{
|
||||
public IFactoryProvider(DiContainer container, Guid factoryId)
|
||||
: base(container, factoryId)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
|
||||
// Do this even when validating in case it has its own dependencies
|
||||
var factory = Container.ResolveId(typeof(IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TContract>), FactoryId);
|
||||
|
||||
injectAction = null;
|
||||
if (Container.IsValidating)
|
||||
{
|
||||
// We assume here that we are creating a user-defined factory so there's
|
||||
// nothing else we can validate here
|
||||
buffer.Add(new ValidationMarker(typeof(TContract)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
((IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TContract>)factory).Create(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Six parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class IFactoryProvider<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TContract> : IFactoryProviderBase<TContract>
|
||||
{
|
||||
public IFactoryProvider(DiContainer container, Guid factoryId)
|
||||
: base(container, factoryId)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 6);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
|
||||
// Do this even when validating in case it has its own dependencies
|
||||
var factory = Container.ResolveId(typeof(IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TContract>), FactoryId);
|
||||
|
||||
injectAction = null;
|
||||
if (Container.IsValidating)
|
||||
{
|
||||
// We assume here that we are creating a user-defined factory so there's
|
||||
// nothing else we can validate here
|
||||
buffer.Add(new ValidationMarker(typeof(TContract)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
((IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TContract>)factory).Create(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ten parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class IFactoryProvider<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10, TContract> : IFactoryProviderBase<TContract>
|
||||
{
|
||||
public IFactoryProvider(DiContainer container, Guid factoryId)
|
||||
: base(container, factoryId)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 10);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
Assert.That(args[6].Type.DerivesFromOrEqual<TParam7>());
|
||||
Assert.That(args[7].Type.DerivesFromOrEqual<TParam8>());
|
||||
Assert.That(args[8].Type.DerivesFromOrEqual<TParam9>());
|
||||
Assert.That(args[9].Type.DerivesFromOrEqual<TParam10>());
|
||||
|
||||
// Do this even when validating in case it has its own dependencies
|
||||
var factory = Container.ResolveId(typeof(IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10, TContract>), FactoryId);
|
||||
|
||||
injectAction = null;
|
||||
if (Container.IsValidating)
|
||||
{
|
||||
// We assume here that we are creating a user-defined factory so there's
|
||||
// nothing else we can validate here
|
||||
buffer.Add(new ValidationMarker(typeof(TContract)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
((IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10, TContract>)factory).Create(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value,
|
||||
(TParam7)args[6].Value,
|
||||
(TParam8)args[7].Value,
|
||||
(TParam9)args[8].Value,
|
||||
(TParam10)args[9].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaf07c2b7ad9f684dac7f1da2ee67f5c
|
||||
timeCreated: 1520700396
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
// The given InjectContext values here should always be non-null
|
||||
public interface IProvider
|
||||
{
|
||||
bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
bool IsCached
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
Type GetInstanceType(InjectContext context);
|
||||
|
||||
// Return an instance which might be not yet injected to.
|
||||
// injectAction should handle the actual injection
|
||||
// This way, providers that call CreateInstance() can store the instance immediately,
|
||||
// and then return that if something gets created during injection that refers back
|
||||
// to the newly created instance
|
||||
void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> instances);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 438b6366f2f1221448e9a71e09ac0329
|
||||
timeCreated: 1461708050
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public static class IProviderExtensions
|
||||
{
|
||||
static readonly List<TypeValuePair> EmptyArgList = new List<TypeValuePair>();
|
||||
|
||||
public static void GetAllInstancesWithInjectSplit(
|
||||
this IProvider creator, InjectContext context, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
creator.GetAllInstancesWithInjectSplit(
|
||||
context, EmptyArgList, out injectAction, buffer);
|
||||
}
|
||||
|
||||
public static void GetAllInstances(
|
||||
this IProvider creator, InjectContext context, List<object> buffer)
|
||||
{
|
||||
creator.GetAllInstances(context, EmptyArgList, buffer);
|
||||
}
|
||||
|
||||
public static void GetAllInstances(
|
||||
this IProvider creator, InjectContext context, List<TypeValuePair> args, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Action injectAction;
|
||||
creator.GetAllInstancesWithInjectSplit(context, args, out injectAction, buffer);
|
||||
|
||||
if (injectAction != null)
|
||||
{
|
||||
injectAction.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public static object TryGetInstance(
|
||||
this IProvider creator, InjectContext context)
|
||||
{
|
||||
return creator.TryGetInstance(context, EmptyArgList);
|
||||
}
|
||||
|
||||
public static object TryGetInstance(
|
||||
this IProvider creator, InjectContext context, List<TypeValuePair> args)
|
||||
{
|
||||
var allInstances = ZenPools.SpawnList<object>();
|
||||
|
||||
try
|
||||
{
|
||||
creator.GetAllInstances(context, args, allInstances);
|
||||
|
||||
if (allInstances.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Assert.That(allInstances.Count == 1,
|
||||
"Provider returned multiple instances when one or zero was expected");
|
||||
|
||||
return allInstances[0];
|
||||
}
|
||||
finally
|
||||
{
|
||||
ZenPools.DespawnList(allInstances);
|
||||
}
|
||||
}
|
||||
|
||||
public static object GetInstance(
|
||||
this IProvider creator, InjectContext context)
|
||||
{
|
||||
return creator.GetInstance(context, EmptyArgList);
|
||||
}
|
||||
|
||||
public static object GetInstance(
|
||||
this IProvider creator, InjectContext context, List<TypeValuePair> args)
|
||||
{
|
||||
var allInstances = ZenPools.SpawnList<object>();
|
||||
|
||||
try
|
||||
{
|
||||
creator.GetAllInstances(context, args, allInstances);
|
||||
|
||||
Assert.That(allInstances.Count > 0,
|
||||
"Provider returned zero instances when one was expected when looking up type '{0}'", context.MemberType);
|
||||
|
||||
Assert.That(allInstances.Count == 1,
|
||||
"Provider returned multiple instances when only one was expected when looking up type '{0}'", context.MemberType);
|
||||
|
||||
return allInstances[0];
|
||||
}
|
||||
finally
|
||||
{
|
||||
ZenPools.DespawnList(allInstances);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2377e3000d1616e4d8cb29c183f216b4
|
||||
timeCreated: 1461708049
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class InstanceProvider : IProvider
|
||||
{
|
||||
readonly object _instance;
|
||||
readonly Type _instanceType;
|
||||
readonly DiContainer _container;
|
||||
readonly Action<InjectContext, object> _instantiateCallback;
|
||||
|
||||
public InstanceProvider(
|
||||
Type instanceType, object instance, DiContainer container, Action<InjectContext, object> instantiateCallback)
|
||||
{
|
||||
_instanceType = instanceType;
|
||||
_instance = instance;
|
||||
_container = container;
|
||||
_instantiateCallback = instantiateCallback;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _instanceType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.That(args.Count == 0);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(_instanceType.DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
object instance = _container.LazyInject(_instance);
|
||||
|
||||
if (_instantiateCallback != null)
|
||||
{
|
||||
_instantiateCallback(context, instance);
|
||||
}
|
||||
};
|
||||
|
||||
buffer.Add(_instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d3d5b3bdf966444099f2dfdf3a313fd
|
||||
timeCreated: 1461708048
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class MethodMultipleProviderUntyped : IProvider
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly Func<InjectContext, IEnumerable<object>> _method;
|
||||
|
||||
public MethodMultipleProviderUntyped(
|
||||
Func<InjectContext, IEnumerable<object>> method,
|
||||
DiContainer container)
|
||||
{
|
||||
_container = container;
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return context.MemberType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
injectAction = null;
|
||||
if (_container.IsValidating && !TypeAnalyzer.ShouldAllowDuringValidation(context.MemberType))
|
||||
{
|
||||
buffer.Add(new ValidationMarker(context.MemberType));
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = _method(context);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw Assert.CreateException(
|
||||
"Method '{0}' returned null when list was expected. Object graph:\n {1}",
|
||||
_method.ToDebugString(), context.GetObjectGraphString());
|
||||
}
|
||||
|
||||
foreach (var obj in result)
|
||||
{
|
||||
buffer.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd9674ffe36a06141afeab1ebbc399f0
|
||||
timeCreated: 1529046908
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class MethodProvider<TReturn> : IProvider
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly Func<InjectContext, TReturn> _method;
|
||||
|
||||
public MethodProvider(
|
||||
Func<InjectContext, TReturn> method,
|
||||
DiContainer container)
|
||||
{
|
||||
_container = container;
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TReturn);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TReturn).DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
injectAction = null;
|
||||
if (_container.IsValidating && !TypeAnalyzer.ShouldAllowDuringValidation(context.MemberType))
|
||||
{
|
||||
buffer.Add(new ValidationMarker(typeof(TReturn)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// We cannot do a null assert here because in some cases they might intentionally
|
||||
// return null
|
||||
buffer.Add(_method(context));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22a7321581383d141b4c11983b83e67b
|
||||
timeCreated: 1461708049
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderMultiple<TReturn> : IProvider
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly Func<InjectContext, IEnumerable<TReturn>> _method;
|
||||
|
||||
public MethodProviderMultiple(
|
||||
Func<InjectContext, IEnumerable<TReturn>> method,
|
||||
DiContainer container)
|
||||
{
|
||||
_container = container;
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TReturn);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TReturn).DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
injectAction = null;
|
||||
if (_container.IsValidating && !TypeAnalyzer.ShouldAllowDuringValidation(context.MemberType))
|
||||
{
|
||||
buffer.Add(new ValidationMarker(typeof(TReturn)));
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = _method(context);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
throw Assert.CreateException(
|
||||
"Method '{0}' returned null when list was expected. Object graph:\n {1}",
|
||||
_method.ToDebugString(), context.GetObjectGraphString());
|
||||
}
|
||||
|
||||
foreach (var obj in result)
|
||||
{
|
||||
buffer.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e5a590d4406d6e46ba319046057db53
|
||||
timeCreated: 1485738781
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderSimple<TReturn> : IProvider
|
||||
{
|
||||
readonly Func<TReturn> _method;
|
||||
|
||||
public MethodProviderSimple(Func<TReturn> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TReturn);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TReturn).DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
injectAction = null;
|
||||
buffer.Add(_method());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eee2b774c35c53641b09b0c1e9620e03
|
||||
timeCreated: 1461708055
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderUntyped : IProvider
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly Func<InjectContext, object> _method;
|
||||
|
||||
public MethodProviderUntyped(
|
||||
Func<InjectContext, object> method,
|
||||
DiContainer container)
|
||||
{
|
||||
_container = container;
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return context.MemberType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
injectAction = null;
|
||||
if (_container.IsValidating && !TypeAnalyzer.ShouldAllowDuringValidation(context.MemberType))
|
||||
{
|
||||
buffer.Add(new ValidationMarker(context.MemberType));
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = _method(context);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
Assert.That(!context.MemberType.IsPrimitive(),
|
||||
"Invalid value returned from FromMethod. Expected non-null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.That(result.GetType().DerivesFromOrEqual(context.MemberType));
|
||||
}
|
||||
|
||||
buffer.Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bddc7ee81ed8fd84cbf60eebf5cb3e41
|
||||
timeCreated: 1465495310
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,499 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
// Zero params
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderWithContainer<TValue> : IProvider
|
||||
{
|
||||
readonly Func<DiContainer, TValue> _method;
|
||||
|
||||
public MethodProviderWithContainer(Func<DiContainer, TValue> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TValue);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
injectAction = null;
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
// Don't do anything when validating, we can't make any assumptions on the given method
|
||||
buffer.Add(new ValidationMarker(typeof(TValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(_method(context.Container));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One params
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderWithContainer<TParam1, TValue> : IProvider
|
||||
{
|
||||
readonly Func<DiContainer, TParam1, TValue> _method;
|
||||
|
||||
public MethodProviderWithContainer(Func<DiContainer, TParam1, TValue> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TValue);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 1);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1)));
|
||||
|
||||
injectAction = null;
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
// Don't do anything when validating, we can't make any assumptions on the given method
|
||||
buffer.Add(new ValidationMarker(typeof(TValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
_method(
|
||||
context.Container,
|
||||
(TParam1)args[0].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two params
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderWithContainer<TParam1, TParam2, TValue> : IProvider
|
||||
{
|
||||
readonly Func<DiContainer, TParam1, TParam2, TValue> _method;
|
||||
|
||||
public MethodProviderWithContainer(Func<DiContainer, TParam1, TParam2, TValue> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TValue);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 2);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1)));
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2)));
|
||||
|
||||
injectAction = null;
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
// Don't do anything when validating, we can't make any assumptions on the given method
|
||||
buffer.Add(new ValidationMarker(typeof(TValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
_method(
|
||||
context.Container,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Three params
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderWithContainer<TParam1, TParam2, TParam3, TValue> : IProvider
|
||||
{
|
||||
readonly Func<DiContainer, TParam1, TParam2, TParam3, TValue> _method;
|
||||
|
||||
public MethodProviderWithContainer(Func<DiContainer, TParam1, TParam2, TParam3, TValue> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TValue);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 3);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1)));
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2)));
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3)));
|
||||
|
||||
injectAction = null;
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
// Don't do anything when validating, we can't make any assumptions on the given method
|
||||
buffer.Add(new ValidationMarker(typeof(TValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
_method(
|
||||
context.Container,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Four params
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderWithContainer<TParam1, TParam2, TParam3, TParam4, TValue> : IProvider
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Func<DiContainer, TParam1, TParam2, TParam3, TParam4, TValue> _method;
|
||||
|
||||
public MethodProviderWithContainer(
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Func<DiContainer, TParam1, TParam2, TParam3, TParam4, TValue> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TValue);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 4);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1)));
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2)));
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3)));
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual(typeof(TParam4)));
|
||||
|
||||
injectAction = null;
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
// Don't do anything when validating, we can't make any assumptions on the given method
|
||||
buffer.Add(new ValidationMarker(typeof(TValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
_method(
|
||||
context.Container,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Five params
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderWithContainer<TParam1, TParam2, TParam3, TParam4, TParam5, TValue> : IProvider
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Func<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TValue> _method;
|
||||
|
||||
public MethodProviderWithContainer(
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Func<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TValue> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TValue);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1)));
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2)));
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3)));
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual(typeof(TParam4)));
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual(typeof(TParam5)));
|
||||
|
||||
injectAction = null;
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
// Don't do anything when validating, we can't make any assumptions on the given method
|
||||
buffer.Add(new ValidationMarker(typeof(TValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
_method(
|
||||
context.Container,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Six params
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderWithContainer<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue> : IProvider
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Func<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue> _method;
|
||||
|
||||
public MethodProviderWithContainer(
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Func<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TValue);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1)));
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2)));
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3)));
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual(typeof(TParam4)));
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual(typeof(TParam5)));
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual(typeof(TParam6)));
|
||||
|
||||
injectAction = null;
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
// Don't do anything when validating, we can't make any assumptions on the given method
|
||||
buffer.Add(new ValidationMarker(typeof(TValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
_method(
|
||||
context.Container,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ten params
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MethodProviderWithContainer<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10, TValue> : IProvider
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Func<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10, TValue> _method;
|
||||
|
||||
public MethodProviderWithContainer(
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Func<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10, TValue> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TValue);
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 10);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1)));
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2)));
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3)));
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual(typeof(TParam4)));
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual(typeof(TParam5)));
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual(typeof(TParam6)));
|
||||
Assert.That(args[6].Type.DerivesFromOrEqual(typeof(TParam7)));
|
||||
Assert.That(args[7].Type.DerivesFromOrEqual(typeof(TParam8)));
|
||||
Assert.That(args[8].Type.DerivesFromOrEqual(typeof(TParam9)));
|
||||
Assert.That(args[9].Type.DerivesFromOrEqual(typeof(TParam10)));
|
||||
|
||||
injectAction = null;
|
||||
if (context.Container.IsValidating)
|
||||
{
|
||||
// Don't do anything when validating, we can't make any assumptions on the given method
|
||||
buffer.Add(new ValidationMarker(typeof(TValue)));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(
|
||||
_method(
|
||||
context.Container,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value,
|
||||
(TParam7)args[6].Value,
|
||||
(TParam8)args[7].Value,
|
||||
(TParam9)args[8].Value,
|
||||
(TParam10)args[9].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb5886f51fc492043bf8d0cc8f4daa2e
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,367 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public abstract class PoolableMemoryPoolProviderBase<TContract> : IProvider
|
||||
{
|
||||
public PoolableMemoryPoolProviderBase(
|
||||
DiContainer container, Guid poolId)
|
||||
{
|
||||
Container = container;
|
||||
PoolId = poolId;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
protected Guid PoolId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
protected DiContainer Container
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return typeof(TContract);
|
||||
}
|
||||
|
||||
public abstract void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer);
|
||||
}
|
||||
|
||||
// Zero parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class PoolableMemoryPoolProvider<TContract, TMemoryPool> : PoolableMemoryPoolProviderBase<TContract>, IValidatable
|
||||
where TContract : IPoolable<IMemoryPool>
|
||||
where TMemoryPool : MemoryPool<IMemoryPool, TContract>
|
||||
{
|
||||
TMemoryPool _pool;
|
||||
|
||||
public PoolableMemoryPoolProvider(
|
||||
DiContainer container, Guid poolId)
|
||||
: base(container, poolId)
|
||||
{
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.That(args.IsEmpty());
|
||||
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_pool == null)
|
||||
{
|
||||
_pool = Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
buffer.Add(_pool.Spawn(_pool));
|
||||
}
|
||||
}
|
||||
|
||||
// One parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class PoolableMemoryPoolProvider<TParam1, TContract, TMemoryPool> : PoolableMemoryPoolProviderBase<TContract>, IValidatable
|
||||
where TContract : IPoolable<TParam1, IMemoryPool>
|
||||
where TMemoryPool : MemoryPool<TParam1, IMemoryPool, TContract>
|
||||
{
|
||||
TMemoryPool _pool;
|
||||
|
||||
public PoolableMemoryPoolProvider(
|
||||
DiContainer container, Guid poolId)
|
||||
: base(container, poolId)
|
||||
{
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 1);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_pool == null)
|
||||
{
|
||||
_pool = Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
buffer.Add(_pool.Spawn((TParam1)args[0].Value, _pool));
|
||||
}
|
||||
}
|
||||
|
||||
// Two parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class PoolableMemoryPoolProvider<TParam1, TParam2, TContract, TMemoryPool> : PoolableMemoryPoolProviderBase<TContract>, IValidatable
|
||||
where TContract : IPoolable<TParam1, TParam2, IMemoryPool>
|
||||
where TMemoryPool : MemoryPool<TParam1, TParam2, IMemoryPool, TContract>
|
||||
{
|
||||
TMemoryPool _pool;
|
||||
|
||||
public PoolableMemoryPoolProvider(
|
||||
DiContainer container, Guid poolId)
|
||||
: base(container, poolId)
|
||||
{
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 2);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_pool == null)
|
||||
{
|
||||
_pool = Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
buffer.Add(_pool.Spawn(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
_pool));
|
||||
}
|
||||
}
|
||||
|
||||
// Three parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class PoolableMemoryPoolProvider<TParam1, TParam2, TParam3, TContract, TMemoryPool> : PoolableMemoryPoolProviderBase<TContract>, IValidatable
|
||||
where TContract : IPoolable<TParam1, TParam2, TParam3, IMemoryPool>
|
||||
where TMemoryPool : MemoryPool<TParam1, TParam2, TParam3, IMemoryPool, TContract>
|
||||
{
|
||||
TMemoryPool _pool;
|
||||
|
||||
public PoolableMemoryPoolProvider(
|
||||
DiContainer container, Guid poolId)
|
||||
: base(container, poolId)
|
||||
{
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 3);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_pool == null)
|
||||
{
|
||||
_pool = Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
buffer.Add(_pool.Spawn(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
_pool));
|
||||
}
|
||||
}
|
||||
|
||||
// Four parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class PoolableMemoryPoolProvider<TParam1, TParam2, TParam3, TParam4, TContract, TMemoryPool> : PoolableMemoryPoolProviderBase<TContract>, IValidatable
|
||||
where TContract : IPoolable<TParam1, TParam2, TParam3, TParam4, IMemoryPool>
|
||||
where TMemoryPool : MemoryPool<TParam1, TParam2, TParam3, TParam4, IMemoryPool, TContract>
|
||||
{
|
||||
TMemoryPool _pool;
|
||||
|
||||
public PoolableMemoryPoolProvider(
|
||||
DiContainer container, Guid poolId)
|
||||
: base(container, poolId)
|
||||
{
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 4);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_pool == null)
|
||||
{
|
||||
_pool = Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
buffer.Add(_pool.Spawn(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
_pool));
|
||||
}
|
||||
}
|
||||
|
||||
// Five parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class PoolableMemoryPoolProvider<TParam1, TParam2, TParam3, TParam4, TParam5, TContract, TMemoryPool> : PoolableMemoryPoolProviderBase<TContract>, IValidatable
|
||||
where TContract : IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, IMemoryPool>
|
||||
where TMemoryPool : MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, IMemoryPool, TContract>
|
||||
{
|
||||
TMemoryPool _pool;
|
||||
|
||||
public PoolableMemoryPoolProvider(
|
||||
DiContainer container, Guid poolId)
|
||||
: base(container, poolId)
|
||||
{
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_pool == null)
|
||||
{
|
||||
_pool = Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
buffer.Add(_pool.Spawn(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
_pool));
|
||||
}
|
||||
}
|
||||
|
||||
// Six parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class PoolableMemoryPoolProvider<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TContract, TMemoryPool> : PoolableMemoryPoolProviderBase<TContract>, IValidatable
|
||||
where TContract : IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, IMemoryPool>
|
||||
where TMemoryPool : MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, IMemoryPool, TContract>
|
||||
{
|
||||
TMemoryPool _pool;
|
||||
|
||||
public PoolableMemoryPoolProvider(
|
||||
DiContainer container, Guid poolId)
|
||||
: base(container, poolId)
|
||||
{
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
public override void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 6);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(typeof(TContract).DerivesFromOrEqual(context.MemberType));
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
|
||||
injectAction = null;
|
||||
|
||||
if (_pool == null)
|
||||
{
|
||||
_pool = Container.ResolveId<TMemoryPool>(PoolId);
|
||||
}
|
||||
|
||||
buffer.Add(_pool.Spawn(
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value,
|
||||
_pool));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6857585e55699ab4da01454c662e0e3b
|
||||
timeCreated: 1528529860
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a029f9358245bf4e99fcb7fcc19ba28
|
||||
folderAsset: yes
|
||||
timeCreated: 1461708046
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public interface IPrefabInstantiator
|
||||
{
|
||||
Type ArgumentTarget
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
List<TypeValuePair> ExtraArguments
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
GameObjectCreationParameters GameObjectCreationParameters
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
GameObject Instantiate(InjectContext context, List<TypeValuePair> args, out Action injectAction);
|
||||
|
||||
UnityEngine.Object GetPrefab(InjectContext context);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45b8fa051fd4fb84b94f6384e6dbe092
|
||||
timeCreated: 1461708050
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,136 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Zenject.Internal;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PrefabInstantiator : IPrefabInstantiator
|
||||
{
|
||||
readonly IPrefabProvider _prefabProvider;
|
||||
readonly DiContainer _container;
|
||||
readonly List<TypeValuePair> _extraArguments;
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
readonly Type _argumentTarget;
|
||||
readonly List<Type> _instantiateCallbackTypes;
|
||||
readonly Action<InjectContext, object> _instantiateCallback;
|
||||
|
||||
public PrefabInstantiator(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Type argumentTarget,
|
||||
IEnumerable<Type> instantiateCallbackTypes,
|
||||
IEnumerable<TypeValuePair> extraArguments,
|
||||
IPrefabProvider prefabProvider,
|
||||
Action<InjectContext, object> instantiateCallback)
|
||||
{
|
||||
_prefabProvider = prefabProvider;
|
||||
_extraArguments = extraArguments.ToList();
|
||||
_container = container;
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
_argumentTarget = argumentTarget;
|
||||
_instantiateCallbackTypes = instantiateCallbackTypes.ToList();
|
||||
_instantiateCallback = instantiateCallback;
|
||||
}
|
||||
|
||||
public GameObjectCreationParameters GameObjectCreationParameters
|
||||
{
|
||||
get { return _gameObjectBindInfo; }
|
||||
}
|
||||
|
||||
public Type ArgumentTarget
|
||||
{
|
||||
get { return _argumentTarget; }
|
||||
}
|
||||
|
||||
public List<TypeValuePair> ExtraArguments
|
||||
{
|
||||
get { return _extraArguments; }
|
||||
}
|
||||
|
||||
public UnityEngine.Object GetPrefab(InjectContext context)
|
||||
{
|
||||
return _prefabProvider.GetPrefab(context);
|
||||
}
|
||||
|
||||
public GameObject Instantiate(InjectContext context, List<TypeValuePair> args, out Action injectAction)
|
||||
{
|
||||
Assert.That(_argumentTarget == null || _argumentTarget.DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
bool shouldMakeActive;
|
||||
var gameObject = _container.CreateAndParentPrefab(
|
||||
GetPrefab(context), _gameObjectBindInfo, context, out shouldMakeActive);
|
||||
Assert.IsNotNull(gameObject);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
var allArgs = ZenPools.SpawnList<TypeValuePair>();
|
||||
|
||||
allArgs.AllocFreeAddRange(_extraArguments);
|
||||
allArgs.AllocFreeAddRange(args);
|
||||
|
||||
if (_argumentTarget == null)
|
||||
{
|
||||
Assert.That(
|
||||
allArgs.IsEmpty(),
|
||||
"Unexpected arguments provided to prefab instantiator. Arguments are not allowed if binding multiple components in the same binding");
|
||||
}
|
||||
|
||||
if (_argumentTarget == null || allArgs.IsEmpty())
|
||||
{
|
||||
_container.InjectGameObject(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
_container.InjectGameObjectForComponentExplicit(
|
||||
gameObject, _argumentTarget, allArgs, context, null);
|
||||
|
||||
Assert.That(allArgs.Count == 0);
|
||||
}
|
||||
|
||||
ZenPools.DespawnList<TypeValuePair>(allArgs);
|
||||
|
||||
if (shouldMakeActive && !_container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (_instantiateCallback != null)
|
||||
{
|
||||
var callbackObjects = ZenPools.SpawnHashSet<object>();
|
||||
|
||||
foreach (var type in _instantiateCallbackTypes)
|
||||
{
|
||||
var obj = gameObject.GetComponentInChildren(type);
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
callbackObjects.Add(obj);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var obj in callbackObjects)
|
||||
{
|
||||
_instantiateCallback(context, obj);
|
||||
}
|
||||
|
||||
ZenPools.DespawnHashSet(callbackObjects);
|
||||
}
|
||||
};
|
||||
|
||||
return gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7dfc3341d0446554996b2969abf2d1ff
|
||||
timeCreated: 1461708051
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PrefabInstantiatorCached : IPrefabInstantiator
|
||||
{
|
||||
readonly IPrefabInstantiator _subInstantiator;
|
||||
|
||||
GameObject _gameObject;
|
||||
|
||||
public PrefabInstantiatorCached(IPrefabInstantiator subInstantiator)
|
||||
{
|
||||
_subInstantiator = subInstantiator;
|
||||
}
|
||||
|
||||
public List<TypeValuePair> ExtraArguments
|
||||
{
|
||||
get { return _subInstantiator.ExtraArguments; }
|
||||
}
|
||||
|
||||
public Type ArgumentTarget
|
||||
{
|
||||
get { return _subInstantiator.ArgumentTarget; }
|
||||
}
|
||||
|
||||
public GameObjectCreationParameters GameObjectCreationParameters
|
||||
{
|
||||
get { return _subInstantiator.GameObjectCreationParameters; }
|
||||
}
|
||||
|
||||
public UnityEngine.Object GetPrefab(InjectContext context)
|
||||
{
|
||||
return _subInstantiator.GetPrefab(context);
|
||||
}
|
||||
|
||||
public GameObject Instantiate(InjectContext context, List<TypeValuePair> args, out Action injectAction)
|
||||
{
|
||||
// We can't really support arguments if we are using the cached value since
|
||||
// the arguments might change when called after the first time
|
||||
Assert.IsEmpty(args);
|
||||
|
||||
if (_gameObject != null)
|
||||
{
|
||||
injectAction = null;
|
||||
return _gameObject;
|
||||
}
|
||||
|
||||
_gameObject = _subInstantiator.Instantiate(context, new List<TypeValuePair>(), out injectAction);
|
||||
return _gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 293ee607ccfdf63458a26d0e6bdebaaa
|
||||
timeCreated: 1461708049
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4248afcd0d89aa54da8d2c34a41c5712
|
||||
folderAsset: yes
|
||||
timeCreated: 1461708046
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public interface IPrefabProvider
|
||||
{
|
||||
UnityEngine.Object GetPrefab(InjectContext context);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b63b8088376c9a499e7f506a237392d
|
||||
timeCreated: 1461708049
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PrefabProvider : IPrefabProvider
|
||||
{
|
||||
readonly UnityEngine.Object _prefab;
|
||||
|
||||
public PrefabProvider(UnityEngine.Object prefab)
|
||||
{
|
||||
Assert.IsNotNull(prefab);
|
||||
_prefab = prefab;
|
||||
}
|
||||
|
||||
public UnityEngine.Object GetPrefab(InjectContext _)
|
||||
{
|
||||
return _prefab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3628433a045792f4297abd34b5a1a34c
|
||||
timeCreated: 1461708049
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PrefabProviderCustom : IPrefabProvider
|
||||
{
|
||||
readonly Func<InjectContext, UnityEngine.Object> _getter;
|
||||
|
||||
public PrefabProviderCustom(Func<InjectContext, UnityEngine.Object> getter)
|
||||
{
|
||||
_getter = getter;
|
||||
}
|
||||
|
||||
public UnityEngine.Object GetPrefab(InjectContext context)
|
||||
{
|
||||
var prefab = _getter(context);
|
||||
Assert.That(prefab != null, "Custom prefab provider returned null");
|
||||
return prefab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6f578cfe9da346348878e4a26617ee0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PrefabProviderResource : IPrefabProvider
|
||||
{
|
||||
readonly string _resourcePath;
|
||||
|
||||
public PrefabProviderResource(string resourcePath)
|
||||
{
|
||||
_resourcePath = resourcePath;
|
||||
}
|
||||
|
||||
public UnityEngine.Object GetPrefab(InjectContext context)
|
||||
{
|
||||
var prefab = (GameObject)Resources.Load(_resourcePath);
|
||||
|
||||
Assert.That(prefab != null,
|
||||
"Expected to find prefab at resource path '{0}'", _resourcePath);
|
||||
|
||||
return prefab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fa6b8670ec5932489c4102d45d987ff
|
||||
timeCreated: 1461708051
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public static class ProviderUtil
|
||||
{
|
||||
public static Type GetTypeToInstantiate(Type contractType, Type concreteType)
|
||||
{
|
||||
#if !(UNITY_WSA && ENABLE_DOTNET)
|
||||
// TODO: Is it possible to do this on WSA?
|
||||
|
||||
if (concreteType.IsOpenGenericType())
|
||||
{
|
||||
return concreteType.MakeGenericType(contractType.GetGenericArguments());
|
||||
}
|
||||
#endif
|
||||
|
||||
Assert.DerivesFromOrEqual(concreteType, contractType);
|
||||
return concreteType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 278c72df466e8b049bc7ce6feb535cb1
|
||||
timeCreated: 1461708049
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class ResolveProvider : IProvider
|
||||
{
|
||||
readonly object _identifier;
|
||||
readonly DiContainer _container;
|
||||
readonly Type _contractType;
|
||||
readonly bool _isOptional;
|
||||
readonly InjectSources _source;
|
||||
readonly bool _matchAll;
|
||||
|
||||
public ResolveProvider(
|
||||
Type contractType, DiContainer container, object identifier,
|
||||
bool isOptional, InjectSources source, bool matchAll)
|
||||
{
|
||||
_contractType = contractType;
|
||||
_identifier = identifier;
|
||||
_container = container;
|
||||
_isOptional = isOptional;
|
||||
_source = source;
|
||||
_matchAll = matchAll;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _contractType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
Assert.That(_contractType.DerivesFromOrEqual(context.MemberType));
|
||||
|
||||
injectAction = null;
|
||||
if (_matchAll)
|
||||
{
|
||||
_container.ResolveAll(GetSubContext(context), buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(_container.Resolve(GetSubContext(context)));
|
||||
}
|
||||
}
|
||||
|
||||
InjectContext GetSubContext(InjectContext parent)
|
||||
{
|
||||
var subContext = parent.CreateSubContext(_contractType, _identifier);
|
||||
|
||||
subContext.SourceType = _source;
|
||||
subContext.Optional = _isOptional;
|
||||
|
||||
return subContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35df94e99ddd0c04c86cf0bcefa85ad8
|
||||
timeCreated: 1461708049
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class ResourceProvider : IProvider
|
||||
{
|
||||
readonly Type _resourceType;
|
||||
readonly string _resourcePath;
|
||||
readonly bool _matchSingle;
|
||||
|
||||
public ResourceProvider(
|
||||
string resourcePath, Type resourceType, bool matchSingle)
|
||||
{
|
||||
_resourceType = resourceType;
|
||||
_resourcePath = resourcePath;
|
||||
_matchSingle = matchSingle;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _resourceType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
if (_matchSingle)
|
||||
{
|
||||
var obj = Resources.Load(_resourcePath, _resourceType);
|
||||
|
||||
Assert.That(obj != null,
|
||||
"Could not find resource at path '{0}' with type '{1}'", _resourcePath, _resourceType);
|
||||
|
||||
// Are there any resource types which can be injected?
|
||||
injectAction = null;
|
||||
buffer.Add(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
var objects = Resources.LoadAll(_resourcePath, _resourceType);
|
||||
|
||||
Assert.That(objects.Length > 0,
|
||||
"Could not find resource at path '{0}' with type '{1}'", _resourcePath, _resourceType);
|
||||
|
||||
// Are there any resource types which can be injected?
|
||||
injectAction = null;
|
||||
|
||||
buffer.AllocFreeAddRange(objects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f16c8e5eed02ac8478e8c236c1677db3
|
||||
timeCreated: 1461708055
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class ScriptableObjectInstanceProvider : IProvider
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly Type _resourceType;
|
||||
readonly List<TypeValuePair> _extraArguments;
|
||||
readonly bool _createNew;
|
||||
readonly object _concreteIdentifier;
|
||||
readonly Action<InjectContext, object> _instantiateCallback;
|
||||
readonly UnityEngine.Object _resource;
|
||||
|
||||
public ScriptableObjectInstanceProvider(
|
||||
UnityEngine.Object resource, Type resourceType,
|
||||
DiContainer container, IEnumerable<TypeValuePair> extraArguments,
|
||||
bool createNew, object concreteIdentifier,
|
||||
Action<InjectContext, object> instantiateCallback)
|
||||
{
|
||||
_container = container;
|
||||
Assert.DerivesFromOrEqual<ScriptableObject>(resourceType);
|
||||
|
||||
_resource = resource;
|
||||
_extraArguments = extraArguments.ToList();
|
||||
_resourceType = resourceType;
|
||||
_createNew = createNew;
|
||||
_concreteIdentifier = concreteIdentifier;
|
||||
_instantiateCallback = instantiateCallback;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _resourceType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
if (_createNew)
|
||||
{
|
||||
buffer.Add(UnityEngine.ScriptableObject.Instantiate(_resource));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.Add(_resource);
|
||||
}
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
for (int i = 0; i < buffer.Count; i++)
|
||||
{
|
||||
var obj = buffer[i];
|
||||
|
||||
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
|
||||
|
||||
extraArgs.AllocFreeAddRange(_extraArguments);
|
||||
extraArgs.AllocFreeAddRange(args);
|
||||
|
||||
_container.InjectExplicit(
|
||||
obj, _resourceType, extraArgs, context, _concreteIdentifier);
|
||||
|
||||
ZenPools.DespawnList(extraArgs);
|
||||
|
||||
if (_instantiateCallback != null)
|
||||
{
|
||||
_instantiateCallback(context, obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd4cee241217b5947b3a223dabefec0a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class ScriptableObjectResourceProvider : IProvider
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly Type _resourceType;
|
||||
readonly string _resourcePath;
|
||||
readonly List<TypeValuePair> _extraArguments;
|
||||
readonly bool _createNew;
|
||||
readonly object _concreteIdentifier;
|
||||
readonly Action<InjectContext, object> _instantiateCallback;
|
||||
|
||||
public ScriptableObjectResourceProvider(
|
||||
string resourcePath, Type resourceType,
|
||||
DiContainer container, IEnumerable<TypeValuePair> extraArguments,
|
||||
bool createNew, object concreteIdentifier,
|
||||
Action<InjectContext, object> instantiateCallback)
|
||||
{
|
||||
_container = container;
|
||||
Assert.DerivesFromOrEqual<ScriptableObject>(resourceType);
|
||||
|
||||
_extraArguments = extraArguments.ToList();
|
||||
_resourceType = resourceType;
|
||||
_resourcePath = resourcePath;
|
||||
_createNew = createNew;
|
||||
_concreteIdentifier = concreteIdentifier;
|
||||
_instantiateCallback = instantiateCallback;
|
||||
}
|
||||
|
||||
public bool IsCached
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool TypeVariesBasedOnMemberType
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Type GetInstanceType(InjectContext context)
|
||||
{
|
||||
return _resourceType;
|
||||
}
|
||||
|
||||
public void GetAllInstancesWithInjectSplit(
|
||||
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
|
||||
{
|
||||
Assert.IsNotNull(context);
|
||||
|
||||
if (_createNew)
|
||||
{
|
||||
var objects = Resources.LoadAll(_resourcePath, _resourceType);
|
||||
|
||||
for (int i = 0; i < objects.Length; i++)
|
||||
{
|
||||
buffer.Add(ScriptableObject.Instantiate(objects[i]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.AllocFreeAddRange(
|
||||
Resources.LoadAll(_resourcePath, _resourceType));
|
||||
}
|
||||
|
||||
Assert.That(buffer.Count > 0,
|
||||
"Could not find resource at path '{0}' with type '{1}'", _resourcePath, _resourceType);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
for (int i = 0; i < buffer.Count; i++)
|
||||
{
|
||||
var obj = buffer[i];
|
||||
|
||||
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
|
||||
|
||||
extraArgs.AllocFreeAddRange(_extraArguments);
|
||||
extraArgs.AllocFreeAddRange(args);
|
||||
|
||||
_container.InjectExplicit(
|
||||
obj, _resourceType, extraArgs, context, _concreteIdentifier);
|
||||
|
||||
ZenPools.DespawnList(extraArgs);
|
||||
|
||||
if (_instantiateCallback != null)
|
||||
{
|
||||
_instantiateCallback(context, obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5753f1f4d468e7649b017dee98c6301d
|
||||
timeCreated: 1486668547
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60492d3348bd7624a9f7f00d1e20ae8e
|
||||
folderAsset: yes
|
||||
timeCreated: 1461708046
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public interface ISubContainerCreator
|
||||
{
|
||||
DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83273a08f84aa9a48b37fe0b1bae0958
|
||||
timeCreated: 1461708051
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorBindInfo
|
||||
{
|
||||
// Null = means no custom default parent
|
||||
public string DefaultParentName
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public bool CreateKernel
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public Type KernelType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d894c838f0dcc34bb38d1311af9ea56
|
||||
timeCreated: 1534923025
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByInstaller : ISubContainerCreator
|
||||
{
|
||||
readonly Type _installerType;
|
||||
readonly DiContainer _container;
|
||||
readonly List<TypeValuePair> _extraArgs;
|
||||
readonly SubContainerCreatorBindInfo _containerBindInfo;
|
||||
|
||||
public SubContainerCreatorByInstaller(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
Type installerType,
|
||||
IEnumerable<TypeValuePair> extraArgs)
|
||||
{
|
||||
_installerType = installerType;
|
||||
_container = container;
|
||||
_extraArgs = extraArgs.ToList();
|
||||
_containerBindInfo = containerBindInfo;
|
||||
|
||||
Assert.That(installerType.DerivesFrom<InstallerBase>(),
|
||||
"Invalid installer type given during bind command. Expected type '{0}' to derive from 'Installer<>'", installerType);
|
||||
}
|
||||
|
||||
public SubContainerCreatorByInstaller(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
Type installerType)
|
||||
: this(container, containerBindInfo, installerType, new List<TypeValuePair>())
|
||||
{
|
||||
}
|
||||
|
||||
public DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
var subContainer = _container.CreateSubContainer();
|
||||
|
||||
SubContainerCreatorUtil.ApplyBindSettings(_containerBindInfo, subContainer);
|
||||
|
||||
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
|
||||
|
||||
extraArgs.AllocFreeAddRange(_extraArgs);
|
||||
extraArgs.AllocFreeAddRange(args);
|
||||
|
||||
var installer = (InstallerBase)subContainer.InstantiateExplicit(
|
||||
_installerType, extraArgs);
|
||||
|
||||
ZenPools.DespawnList(extraArgs);
|
||||
|
||||
installer.InstallBindings();
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d932bdf1cc240394a94c9fd81dfa9218
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByInstance : ISubContainerCreator
|
||||
{
|
||||
readonly DiContainer _subcontainer;
|
||||
|
||||
public SubContainerCreatorByInstance(DiContainer subcontainer)
|
||||
{
|
||||
_subcontainer = subcontainer;
|
||||
}
|
||||
|
||||
public DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.That(args.IsEmpty());
|
||||
|
||||
injectAction = null;
|
||||
|
||||
// It is assumed here that the subcontainer has already had ResolveRoots called elsewhere
|
||||
// Since most likely you are adding a subcontainer that is already in a context or
|
||||
// something rather than directly using DiContainer.CreateSubContainer
|
||||
return _subcontainer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ea58c024bbd4e846be07059bf23c524
|
||||
timeCreated: 1535189469
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByInstanceGetter : ISubContainerCreator
|
||||
{
|
||||
readonly Func<InjectContext, DiContainer> _subcontainerGetter;
|
||||
|
||||
public SubContainerCreatorByInstanceGetter(
|
||||
Func<InjectContext, DiContainer> subcontainerGetter)
|
||||
{
|
||||
_subcontainerGetter = subcontainerGetter;
|
||||
}
|
||||
|
||||
public DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.That(args.IsEmpty());
|
||||
|
||||
injectAction = null;
|
||||
|
||||
// It is assumed here that the subcontainer has already had ResolveRoots called elsewhere
|
||||
// Since most likely you are adding a subcontainer that is already in a context or
|
||||
// something rather than directly using DiContainer.CreateSubContainer
|
||||
return _subcontainerGetter(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 164cf97cfe8f32441beb85b9b3c05868
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+390
@@ -0,0 +1,390 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
// Zero parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public abstract class SubContainerCreatorByMethodBase : ISubContainerCreator
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly SubContainerCreatorBindInfo _containerBindInfo;
|
||||
|
||||
public SubContainerCreatorByMethodBase(
|
||||
DiContainer container, SubContainerCreatorBindInfo containerBindInfo)
|
||||
{
|
||||
_container = container;
|
||||
_containerBindInfo = containerBindInfo;
|
||||
}
|
||||
|
||||
public abstract DiContainer CreateSubContainer(
|
||||
List<TypeValuePair> args, InjectContext context, out Action injectAction);
|
||||
|
||||
protected DiContainer CreateEmptySubContainer()
|
||||
{
|
||||
var subContainer = _container.CreateSubContainer();
|
||||
SubContainerCreatorUtil.ApplyBindSettings(_containerBindInfo, subContainer);
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByMethod : SubContainerCreatorByMethodBase
|
||||
{
|
||||
readonly Action<DiContainer> _installMethod;
|
||||
|
||||
public SubContainerCreatorByMethod(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
Action<DiContainer> installMethod)
|
||||
: base(container, containerBindInfo)
|
||||
{
|
||||
_installMethod = installMethod;
|
||||
}
|
||||
|
||||
public override DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.IsEmpty(args);
|
||||
|
||||
var subContainer = CreateEmptySubContainer();
|
||||
|
||||
_installMethod(subContainer);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// One parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByMethod<TParam1> : SubContainerCreatorByMethodBase
|
||||
{
|
||||
readonly Action<DiContainer, TParam1> _installMethod;
|
||||
|
||||
public SubContainerCreatorByMethod(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
Action<DiContainer, TParam1> installMethod)
|
||||
: base(container, containerBindInfo)
|
||||
{
|
||||
_installMethod = installMethod;
|
||||
}
|
||||
|
||||
public override DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 1);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
|
||||
var subContainer = CreateEmptySubContainer();
|
||||
|
||||
_installMethod(subContainer, (TParam1)args[0].Value);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Two parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByMethod<TParam1, TParam2> : SubContainerCreatorByMethodBase
|
||||
{
|
||||
readonly Action<DiContainer, TParam1, TParam2> _installMethod;
|
||||
|
||||
public SubContainerCreatorByMethod(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
Action<DiContainer, TParam1, TParam2> installMethod)
|
||||
: base(container, containerBindInfo)
|
||||
{
|
||||
_installMethod = installMethod;
|
||||
}
|
||||
|
||||
public override DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 2);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
|
||||
var subContainer = CreateEmptySubContainer();
|
||||
|
||||
_installMethod(
|
||||
subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Three parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByMethod<TParam1, TParam2, TParam3> : SubContainerCreatorByMethodBase
|
||||
{
|
||||
readonly Action<DiContainer, TParam1, TParam2, TParam3> _installMethod;
|
||||
|
||||
public SubContainerCreatorByMethod(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
Action<DiContainer, TParam1, TParam2, TParam3> installMethod)
|
||||
: base(container, containerBindInfo)
|
||||
{
|
||||
_installMethod = installMethod;
|
||||
}
|
||||
|
||||
public override DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 3);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
|
||||
var subContainer = CreateEmptySubContainer();
|
||||
|
||||
_installMethod(
|
||||
subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Four parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByMethod<TParam1, TParam2, TParam3, TParam4> : SubContainerCreatorByMethodBase
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4> _installMethod;
|
||||
|
||||
public SubContainerCreatorByMethod(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4> installMethod)
|
||||
: base(container, containerBindInfo)
|
||||
{
|
||||
_installMethod = installMethod;
|
||||
}
|
||||
|
||||
public override DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 4);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
|
||||
var subContainer = CreateEmptySubContainer();
|
||||
|
||||
_installMethod(
|
||||
subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Five parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByMethod<TParam1, TParam2, TParam3, TParam4, TParam5> : SubContainerCreatorByMethodBase
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5> _installMethod;
|
||||
|
||||
public SubContainerCreatorByMethod(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5> installMethod)
|
||||
: base(container, containerBindInfo)
|
||||
{
|
||||
_installMethod = installMethod;
|
||||
}
|
||||
|
||||
public override DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
|
||||
var subContainer = CreateEmptySubContainer();
|
||||
|
||||
_installMethod(
|
||||
subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Six parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByMethod<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> : SubContainerCreatorByMethodBase
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> _installMethod;
|
||||
|
||||
public SubContainerCreatorByMethod(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> installMethod)
|
||||
: base(container, containerBindInfo)
|
||||
{
|
||||
_installMethod = installMethod;
|
||||
}
|
||||
|
||||
public override DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
|
||||
var subContainer = CreateEmptySubContainer();
|
||||
|
||||
_installMethod(
|
||||
subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// 10 parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByMethod<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> : SubContainerCreatorByMethodBase
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> _installMethod;
|
||||
|
||||
public SubContainerCreatorByMethod(
|
||||
DiContainer container,
|
||||
SubContainerCreatorBindInfo containerBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> installMethod)
|
||||
: base(container, containerBindInfo)
|
||||
{
|
||||
_installMethod = installMethod;
|
||||
}
|
||||
|
||||
public override DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext context, out Action injectAction)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 10);
|
||||
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
Assert.That(args[6].Type.DerivesFromOrEqual<TParam7>());
|
||||
Assert.That(args[7].Type.DerivesFromOrEqual<TParam8>());
|
||||
Assert.That(args[8].Type.DerivesFromOrEqual<TParam9>());
|
||||
Assert.That(args[9].Type.DerivesFromOrEqual<TParam10>());
|
||||
|
||||
var subContainer = CreateEmptySubContainer();
|
||||
|
||||
_installMethod(
|
||||
subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value,
|
||||
(TParam7)args[6].Value,
|
||||
(TParam8)args[7].Value,
|
||||
(TParam9)args[8].Value,
|
||||
(TParam10)args[9].Value);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
subContainer.ResolveRoots();
|
||||
};
|
||||
|
||||
return subContainer;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f4bb37c4e2a5bf44865ed1ab3bef21e
|
||||
timeCreated: 1461708050
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+366
@@ -0,0 +1,366 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using ModestTree;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public abstract class SubContainerCreatorByNewGameObjectDynamicContext : SubContainerCreatorDynamicContext
|
||||
{
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectDynamicContext(
|
||||
DiContainer container, GameObjectCreationParameters gameObjectBindInfo)
|
||||
: base(container)
|
||||
{
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
}
|
||||
|
||||
protected override GameObject CreateGameObject(InjectContext context, out bool shouldMakeActive)
|
||||
{
|
||||
shouldMakeActive = true;
|
||||
var gameObject = Container.CreateEmptyGameObject(_gameObjectBindInfo, null);
|
||||
gameObject.SetActive(false);
|
||||
return gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectInstaller : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly Type _installerType;
|
||||
readonly List<TypeValuePair> _extraArgs;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectInstaller(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Type installerType, List<TypeValuePair> extraArgs)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerType = installerType;
|
||||
_extraArgs = extraArgs;
|
||||
|
||||
Assert.That(installerType.DerivesFrom<InstallerBase>(),
|
||||
"Invalid installer type given during bind command. Expected type '{0}' to derive from 'Installer<>'", installerType);
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
|
||||
|
||||
extraArgs.AllocFreeAddRange(_extraArgs);
|
||||
extraArgs.AllocFreeAddRange(args);
|
||||
|
||||
var installer = (InstallerBase)subContainer.InstantiateExplicit(
|
||||
_installerType, extraArgs);
|
||||
|
||||
ZenPools.DespawnList(extraArgs);
|
||||
|
||||
installer.InstallBindings();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectMethod : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly Action<DiContainer> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectMethod(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Action<DiContainer> installerMethod)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.That(args.IsEmpty());
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(_installerMethod));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectMethod<TParam1> : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly Action<DiContainer, TParam1> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectMethod(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Action<DiContainer, TParam1> installerMethod)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 1);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer, (TParam1)args[0].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectMethod<TParam1, TParam2> : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly Action<DiContainer, TParam1, TParam2> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectMethod(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Action<DiContainer, TParam1, TParam2> installerMethod)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 2);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectMethod<TParam1, TParam2, TParam3> : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly Action<DiContainer, TParam1, TParam2, TParam3> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectMethod(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Action<DiContainer, TParam1, TParam2, TParam3> installerMethod)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 3);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectMethod<TParam1, TParam2, TParam3, TParam4> : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectMethod(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4> installerMethod)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 4);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectMethod<TParam1, TParam2, TParam3, TParam4, TParam5> : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectMethod(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5> installerMethod)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectMethod<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectMethod(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> installerMethod)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewGameObjectMethod<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> : SubContainerCreatorByNewGameObjectDynamicContext
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewGameObjectMethod(
|
||||
DiContainer container,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> installerMethod)
|
||||
: base(container, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 10);
|
||||
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
Assert.That(args[6].Type.DerivesFromOrEqual<TParam7>());
|
||||
Assert.That(args[7].Type.DerivesFromOrEqual<TParam8>());
|
||||
Assert.That(args[8].Type.DerivesFromOrEqual<TParam9>());
|
||||
Assert.That(args[9].Type.DerivesFromOrEqual<TParam10>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value,
|
||||
(TParam7)args[6].Value,
|
||||
(TParam8)args[7].Value,
|
||||
(TParam9)args[8].Value,
|
||||
(TParam10)args[9].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c2c6880c82d78140818fe3204a0279b
|
||||
timeCreated: 1538467080
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefab : ISubContainerCreator
|
||||
{
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
readonly IPrefabProvider _prefabProvider;
|
||||
readonly DiContainer _container;
|
||||
|
||||
public SubContainerCreatorByNewPrefab(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo)
|
||||
{
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
_prefabProvider = prefabProvider;
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public DiContainer CreateSubContainer(
|
||||
List<TypeValuePair> args, InjectContext parentContext, out Action injectAction)
|
||||
{
|
||||
Assert.That(args.IsEmpty());
|
||||
|
||||
var prefab = _prefabProvider.GetPrefab(parentContext);
|
||||
|
||||
bool shouldMakeActive;
|
||||
var gameObject = _container.CreateAndParentPrefab(
|
||||
prefab, _gameObjectBindInfo, null, out shouldMakeActive);
|
||||
|
||||
var context = gameObject.GetComponent<GameObjectContext>();
|
||||
|
||||
Assert.That(context != null,
|
||||
"Expected prefab with name '{0}' to contain a component of type 'GameObjectContext' on the root", prefab.name);
|
||||
|
||||
context.Install(_container);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
// Note: We don't need to call ResolveRoots here because GameObjectContext does this for us
|
||||
_container.Inject(context);
|
||||
|
||||
if (shouldMakeActive && !_container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return context.Container;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17fc7cad09fe4e94f939551c85abf6d9
|
||||
timeCreated: 1486859770
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+377
@@ -0,0 +1,377 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using ModestTree;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public abstract class SubContainerCreatorByNewPrefabDynamicContext : SubContainerCreatorDynamicContext
|
||||
{
|
||||
readonly IPrefabProvider _prefabProvider;
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
|
||||
public SubContainerCreatorByNewPrefabDynamicContext(
|
||||
DiContainer container,
|
||||
IPrefabProvider prefabProvider, GameObjectCreationParameters gameObjectBindInfo)
|
||||
: base(container)
|
||||
{
|
||||
_prefabProvider = prefabProvider;
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
}
|
||||
|
||||
protected override GameObject CreateGameObject(InjectContext context, out bool shouldMakeActive)
|
||||
{
|
||||
var prefab = _prefabProvider.GetPrefab(context);
|
||||
|
||||
var gameObj = Container.CreateAndParentPrefab(
|
||||
prefab, _gameObjectBindInfo, null, out shouldMakeActive);
|
||||
|
||||
if (gameObj.GetComponent<GameObjectContext>() != null)
|
||||
{
|
||||
throw Assert.CreateException(
|
||||
"Found GameObjectContext already attached to prefab with name '{0}'! When using ByNewPrefabMethod or ByNewPrefabInstaller, the GameObjectContext is added to the prefab dynamically", prefab.name);
|
||||
}
|
||||
|
||||
return gameObj;
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabInstaller : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly Type _installerType;
|
||||
readonly List<TypeValuePair> _extraArgs;
|
||||
|
||||
public SubContainerCreatorByNewPrefabInstaller(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Type installerType, List<TypeValuePair> extraArgs)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerType = installerType;
|
||||
_extraArgs = extraArgs;
|
||||
|
||||
Assert.That(installerType.DerivesFrom<InstallerBase>(),
|
||||
"Invalid installer type given during bind command. Expected type '{0}' to derive from 'Installer<>'", installerType);
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
|
||||
|
||||
extraArgs.AllocFreeAddRange(_extraArgs);
|
||||
extraArgs.AllocFreeAddRange(args);
|
||||
|
||||
var installer = (InstallerBase)subContainer.InstantiateExplicit(
|
||||
_installerType, extraArgs);
|
||||
|
||||
ZenPools.DespawnList(extraArgs);
|
||||
|
||||
installer.InstallBindings();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabMethod : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly Action<DiContainer> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewPrefabMethod(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Action<DiContainer> installerMethod)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.That(args.IsEmpty());
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(_installerMethod));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabMethod<TParam1> : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly Action<DiContainer, TParam1> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewPrefabMethod(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Action<DiContainer, TParam1> installerMethod)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 1);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer, (TParam1)args[0].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabMethod<TParam1, TParam2> : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly Action<DiContainer, TParam1, TParam2> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewPrefabMethod(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Action<DiContainer, TParam1, TParam2> installerMethod)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 2);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabMethod<TParam1, TParam2, TParam3> : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly Action<DiContainer, TParam1, TParam2, TParam3> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewPrefabMethod(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
Action<DiContainer, TParam1, TParam2, TParam3> installerMethod)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 3);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabMethod<TParam1, TParam2, TParam3, TParam4> : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewPrefabMethod(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4> installerMethod)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 4);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabMethod<TParam1, TParam2, TParam3, TParam4, TParam5> : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewPrefabMethod(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5> installerMethod)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabMethod<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewPrefabMethod(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6> installerMethod)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 5);
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabMethod<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> : SubContainerCreatorByNewPrefabDynamicContext
|
||||
{
|
||||
readonly
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> _installerMethod;
|
||||
|
||||
public SubContainerCreatorByNewPrefabMethod(
|
||||
DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> installerMethod)
|
||||
: base(container, prefabProvider, gameObjectBindInfo)
|
||||
{
|
||||
_installerMethod = installerMethod;
|
||||
}
|
||||
|
||||
protected override void AddInstallers(List<TypeValuePair> args, GameObjectContext context)
|
||||
{
|
||||
Assert.IsEqual(args.Count, 10);
|
||||
|
||||
Assert.That(args[0].Type.DerivesFromOrEqual<TParam1>());
|
||||
Assert.That(args[1].Type.DerivesFromOrEqual<TParam2>());
|
||||
Assert.That(args[2].Type.DerivesFromOrEqual<TParam3>());
|
||||
Assert.That(args[3].Type.DerivesFromOrEqual<TParam4>());
|
||||
Assert.That(args[4].Type.DerivesFromOrEqual<TParam5>());
|
||||
Assert.That(args[5].Type.DerivesFromOrEqual<TParam6>());
|
||||
Assert.That(args[6].Type.DerivesFromOrEqual<TParam7>());
|
||||
Assert.That(args[7].Type.DerivesFromOrEqual<TParam8>());
|
||||
Assert.That(args[8].Type.DerivesFromOrEqual<TParam9>());
|
||||
Assert.That(args[9].Type.DerivesFromOrEqual<TParam10>());
|
||||
|
||||
context.AddNormalInstaller(
|
||||
new ActionInstaller(subContainer =>
|
||||
{
|
||||
_installerMethod(subContainer,
|
||||
(TParam1)args[0].Value,
|
||||
(TParam2)args[1].Value,
|
||||
(TParam3)args[2].Value,
|
||||
(TParam4)args[3].Value,
|
||||
(TParam5)args[4].Value,
|
||||
(TParam6)args[5].Value,
|
||||
(TParam7)args[6].Value,
|
||||
(TParam8)args[7].Value,
|
||||
(TParam9)args[8].Value,
|
||||
(TParam10)args[9].Value);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53f151c86cd3c4c46ada71b737004d36
|
||||
timeCreated: 1505722322
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerCreatorByNewPrefabWithParams : ISubContainerCreator
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly IPrefabProvider _prefabProvider;
|
||||
readonly Type _installerType;
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
|
||||
public SubContainerCreatorByNewPrefabWithParams(
|
||||
Type installerType, DiContainer container, IPrefabProvider prefabProvider,
|
||||
GameObjectCreationParameters gameObjectBindInfo)
|
||||
{
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
_prefabProvider = prefabProvider;
|
||||
_container = container;
|
||||
_installerType = installerType;
|
||||
}
|
||||
|
||||
protected DiContainer Container
|
||||
{
|
||||
get { return _container; }
|
||||
}
|
||||
|
||||
IEnumerable<InjectableInfo> GetAllInjectableIncludingBaseTypes()
|
||||
{
|
||||
var info = TypeAnalyzer.GetInfo(_installerType);
|
||||
|
||||
while (info != null)
|
||||
{
|
||||
foreach (var injectable in info.AllInjectables)
|
||||
{
|
||||
yield return injectable;
|
||||
}
|
||||
|
||||
info = info.BaseTypeInfo;
|
||||
}
|
||||
}
|
||||
|
||||
DiContainer CreateTempContainer(List<TypeValuePair> args)
|
||||
{
|
||||
var tempSubContainer = Container.CreateSubContainer();
|
||||
|
||||
var allInjectables = GetAllInjectableIncludingBaseTypes();
|
||||
|
||||
foreach (var argPair in args)
|
||||
{
|
||||
// We need to intelligently match on the exact parameters here to avoid the issue
|
||||
// brought up in github issue #217
|
||||
var match = allInjectables
|
||||
.Where(x => argPair.Type.DerivesFromOrEqual(x.MemberType))
|
||||
.OrderBy(x => ZenUtilInternal.GetInheritanceDelta(argPair.Type, x.MemberType)).FirstOrDefault();
|
||||
|
||||
Assert.That(match != null,
|
||||
"Could not find match for argument type '{0}' when injecting into sub container installer '{1}'",
|
||||
argPair.Type, _installerType);
|
||||
|
||||
tempSubContainer.Bind(match.MemberType)
|
||||
.FromInstance(argPair.Value).WhenInjectedInto(_installerType);
|
||||
}
|
||||
|
||||
return tempSubContainer;
|
||||
}
|
||||
|
||||
public DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext parentContext, out Action injectAction)
|
||||
{
|
||||
Assert.That(!args.IsEmpty());
|
||||
|
||||
var prefab = _prefabProvider.GetPrefab(parentContext);
|
||||
var tempContainer = CreateTempContainer(args);
|
||||
|
||||
bool shouldMakeActive;
|
||||
var gameObject = tempContainer.CreateAndParentPrefab(
|
||||
prefab, _gameObjectBindInfo, null, out shouldMakeActive);
|
||||
|
||||
var context = gameObject.GetComponent<GameObjectContext>();
|
||||
|
||||
Assert.That(context != null,
|
||||
"Expected prefab with name '{0}' to container a component of type 'GameObjectContext'", prefab.name);
|
||||
|
||||
context.Install(tempContainer);
|
||||
|
||||
injectAction = () =>
|
||||
{
|
||||
// Note: We don't need to call ResolveRoots here because GameObjectContext does this for us
|
||||
tempContainer.Inject(context);
|
||||
|
||||
if (shouldMakeActive && !_container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return context.Container;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user