Update Project
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
namespace Zenject
|
||||
{
|
||||
public interface IBindingFinalizer
|
||||
{
|
||||
BindingInheritanceMethods BindingInheritanceMethod
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
void FinalizeBinding(DiContainer container);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0c24b30b6678884db62f15947ec943c
|
||||
timeCreated: 1461708053
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class NullBindingFinalizer : IBindingFinalizer
|
||||
{
|
||||
public BindingInheritanceMethods BindingInheritanceMethod
|
||||
{
|
||||
get { return BindingInheritanceMethods.None; }
|
||||
}
|
||||
|
||||
public void FinalizeBinding(DiContainer container)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b41a20eb0faa1041bf6aa0bfcc76064
|
||||
timeCreated: 1480010956
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,158 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PrefabBindingFinalizer : ProviderBindingFinalizer
|
||||
{
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
readonly UnityEngine.Object _prefab;
|
||||
readonly Func<Type, IPrefabInstantiator, IProvider> _providerFactory;
|
||||
|
||||
public PrefabBindingFinalizer(
|
||||
BindInfo bindInfo,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
UnityEngine.Object prefab, Func<Type, IPrefabInstantiator, IProvider> providerFactory)
|
||||
: base(bindInfo)
|
||||
{
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
_prefab = prefab;
|
||||
_providerFactory = providerFactory;
|
||||
}
|
||||
|
||||
protected override void OnFinalizeBinding(DiContainer container)
|
||||
{
|
||||
if (BindInfo.ToChoice == ToChoices.Self)
|
||||
{
|
||||
Assert.IsEmpty(BindInfo.ToTypes);
|
||||
FinalizeBindingSelf(container);
|
||||
}
|
||||
else
|
||||
{
|
||||
FinalizeBindingConcrete(container, BindInfo.ToTypes);
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingConcrete(DiContainer container, List<Type> concreteTypes)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) =>
|
||||
_providerFactory(
|
||||
concreteType,
|
||||
new PrefabInstantiator(
|
||||
container,
|
||||
_gameObjectBindInfo,
|
||||
concreteType,
|
||||
concreteTypes,
|
||||
BindInfo.Arguments,
|
||||
new PrefabProvider(_prefab),
|
||||
BindInfo.InstantiatedCallback)));
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
var argumentTarget = concreteTypes.OnlyOrDefault();
|
||||
|
||||
if (argumentTarget == null)
|
||||
{
|
||||
Assert.That(BindInfo.Arguments.IsEmpty(),
|
||||
"Cannot provide arguments to prefab instantiator when using more than one concrete type");
|
||||
}
|
||||
|
||||
var prefabCreator = new PrefabInstantiatorCached(
|
||||
new PrefabInstantiator(
|
||||
container,
|
||||
_gameObjectBindInfo,
|
||||
argumentTarget,
|
||||
concreteTypes,
|
||||
BindInfo.Arguments,
|
||||
new PrefabProvider(_prefab),
|
||||
BindInfo.InstantiatedCallback));
|
||||
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) => BindingUtil.CreateCachedProvider(
|
||||
_providerFactory(concreteType, prefabCreator)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingSelf(DiContainer container)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) =>
|
||||
_providerFactory(
|
||||
contractType,
|
||||
new PrefabInstantiator(
|
||||
container,
|
||||
_gameObjectBindInfo,
|
||||
contractType,
|
||||
BindInfo.ContractTypes,
|
||||
BindInfo.Arguments,
|
||||
new PrefabProvider(_prefab),
|
||||
BindInfo.InstantiatedCallback)));
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
var argumentTarget = BindInfo.ContractTypes.OnlyOrDefault();
|
||||
|
||||
if (argumentTarget == null)
|
||||
{
|
||||
Assert.That(BindInfo.Arguments.IsEmpty(),
|
||||
"Cannot provide arguments to prefab instantiator when using more than one concrete type");
|
||||
}
|
||||
|
||||
var prefabCreator = new PrefabInstantiatorCached(
|
||||
new PrefabInstantiator(
|
||||
container,
|
||||
_gameObjectBindInfo,
|
||||
argumentTarget,
|
||||
BindInfo.ContractTypes,
|
||||
BindInfo.Arguments,
|
||||
new PrefabProvider(_prefab),
|
||||
BindInfo.InstantiatedCallback));
|
||||
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) =>
|
||||
BindingUtil.CreateCachedProvider(
|
||||
_providerFactory(contractType, prefabCreator)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10487121a4674d74884ee65e70762e35
|
||||
timeCreated: 1461708048
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,157 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PrefabResourceBindingFinalizer : ProviderBindingFinalizer
|
||||
{
|
||||
readonly GameObjectCreationParameters _gameObjectBindInfo;
|
||||
readonly string _resourcePath;
|
||||
readonly Func<Type, IPrefabInstantiator, IProvider> _providerFactory;
|
||||
|
||||
public PrefabResourceBindingFinalizer(
|
||||
BindInfo bindInfo,
|
||||
GameObjectCreationParameters gameObjectBindInfo,
|
||||
string resourcePath, Func<Type, IPrefabInstantiator, IProvider> providerFactory)
|
||||
: base(bindInfo)
|
||||
{
|
||||
_gameObjectBindInfo = gameObjectBindInfo;
|
||||
_resourcePath = resourcePath;
|
||||
_providerFactory = providerFactory;
|
||||
}
|
||||
|
||||
protected override void OnFinalizeBinding(DiContainer container)
|
||||
{
|
||||
if (BindInfo.ToChoice == ToChoices.Self)
|
||||
{
|
||||
Assert.IsEmpty(BindInfo.ToTypes);
|
||||
FinalizeBindingSelf(container);
|
||||
}
|
||||
else
|
||||
{
|
||||
FinalizeBindingConcrete(container, BindInfo.ToTypes);
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingConcrete(DiContainer container, List<Type> concreteTypes)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) =>
|
||||
_providerFactory(
|
||||
concreteType,
|
||||
new PrefabInstantiator(
|
||||
container,
|
||||
_gameObjectBindInfo,
|
||||
concreteType,
|
||||
concreteTypes,
|
||||
BindInfo.Arguments,
|
||||
new PrefabProviderResource(_resourcePath),
|
||||
BindInfo.InstantiatedCallback)));
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
var argumentTarget = concreteTypes.OnlyOrDefault();
|
||||
|
||||
if (argumentTarget == null)
|
||||
{
|
||||
Assert.That(BindInfo.Arguments.IsEmpty(),
|
||||
"Cannot provide arguments to prefab instantiator when using more than one concrete type");
|
||||
}
|
||||
|
||||
var prefabCreator = new PrefabInstantiatorCached(
|
||||
new PrefabInstantiator(
|
||||
container,
|
||||
_gameObjectBindInfo,
|
||||
argumentTarget,
|
||||
concreteTypes,
|
||||
BindInfo.Arguments,
|
||||
new PrefabProviderResource(_resourcePath),
|
||||
BindInfo.InstantiatedCallback));
|
||||
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) => BindingUtil.CreateCachedProvider(
|
||||
_providerFactory(concreteType, prefabCreator)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingSelf(DiContainer container)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) =>
|
||||
_providerFactory(
|
||||
contractType,
|
||||
new PrefabInstantiator(
|
||||
container,
|
||||
_gameObjectBindInfo,
|
||||
contractType,
|
||||
BindInfo.ContractTypes,
|
||||
BindInfo.Arguments,
|
||||
new PrefabProviderResource(_resourcePath),
|
||||
BindInfo.InstantiatedCallback)));
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
var argumentTarget = BindInfo.ContractTypes.OnlyOrDefault();
|
||||
|
||||
if (argumentTarget == null)
|
||||
{
|
||||
Assert.That(BindInfo.Arguments.IsEmpty(),
|
||||
"Cannot provide arguments to prefab instantiator when using more than one concrete type");
|
||||
}
|
||||
|
||||
var prefabCreator = new PrefabInstantiatorCached(
|
||||
new PrefabInstantiator(
|
||||
container,
|
||||
_gameObjectBindInfo,
|
||||
argumentTarget,
|
||||
BindInfo.ContractTypes,
|
||||
BindInfo.Arguments,
|
||||
new PrefabProviderResource(_resourcePath),
|
||||
BindInfo.InstantiatedCallback));
|
||||
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) =>
|
||||
BindingUtil.CreateCachedProvider(
|
||||
_providerFactory(contractType, prefabCreator)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b851ccfb909f66c4587d694f6e37b279
|
||||
timeCreated: 1461708053
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,248 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
using Zenject.Internal;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public abstract class ProviderBindingFinalizer : IBindingFinalizer
|
||||
{
|
||||
public ProviderBindingFinalizer(BindInfo bindInfo)
|
||||
{
|
||||
BindInfo = bindInfo;
|
||||
}
|
||||
|
||||
public BindingInheritanceMethods BindingInheritanceMethod
|
||||
{
|
||||
get { return BindInfo.BindingInheritanceMethod; }
|
||||
}
|
||||
|
||||
protected BindInfo BindInfo
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
protected ScopeTypes GetScope()
|
||||
{
|
||||
if (BindInfo.Scope == ScopeTypes.Unset)
|
||||
{
|
||||
// If condition is set then it's probably fine to allow the default of transient
|
||||
Assert.That(!BindInfo.RequireExplicitScope || BindInfo.Condition != null,
|
||||
"Scope must be set for the previous binding! Please either specify AsTransient, AsCached, or AsSingle. Last binding: Contract: {0}, Identifier: {1} {2}",
|
||||
BindInfo.ContractTypes.Select(x => x.PrettyName()).Join(", "), BindInfo.Identifier,
|
||||
BindInfo.ContextInfo != null ? "Context: '{0}'".Fmt(BindInfo.ContextInfo) : "");
|
||||
return ScopeTypes.Transient;
|
||||
}
|
||||
|
||||
return BindInfo.Scope;
|
||||
}
|
||||
|
||||
public void FinalizeBinding(DiContainer container)
|
||||
{
|
||||
if (BindInfo.ContractTypes.Count == 0)
|
||||
{
|
||||
// We could assert her instead but it is nice when used with things like
|
||||
// BindInterfaces() (and there aren't any interfaces) to allow
|
||||
// interfaces to be added later
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
OnFinalizeBinding(container);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Assert.CreateException(
|
||||
e, "Error while finalizing previous binding! Contract: {0}, Identifier: {1} {2}",
|
||||
BindInfo.ContractTypes.Select(x => x.PrettyName()).Join(", "), BindInfo.Identifier,
|
||||
BindInfo.ContextInfo != null ? "Context: '{0}'".Fmt(BindInfo.ContextInfo) : "");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void OnFinalizeBinding(DiContainer container);
|
||||
|
||||
protected void RegisterProvider<TContract>(
|
||||
DiContainer container, IProvider provider)
|
||||
{
|
||||
RegisterProvider(container, typeof(TContract), provider);
|
||||
}
|
||||
|
||||
protected void RegisterProvider(
|
||||
DiContainer container, Type contractType, IProvider provider)
|
||||
{
|
||||
if (BindInfo.OnlyBindIfNotBound && container.HasBindingId(contractType, BindInfo.Identifier))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
container.RegisterProvider(
|
||||
new BindingId(contractType, BindInfo.Identifier),
|
||||
BindInfo.Condition,
|
||||
provider, BindInfo.NonLazy);
|
||||
|
||||
if (contractType.IsValueType() && !(contractType.IsGenericType() && contractType.GetGenericTypeDefinition() == typeof(Nullable<>)))
|
||||
{
|
||||
var nullableType = typeof(Nullable<>).MakeGenericType(contractType);
|
||||
|
||||
// Also bind to nullable primitives
|
||||
// this is useful so that we can have optional primitive dependencies
|
||||
container.RegisterProvider(
|
||||
new BindingId(nullableType, BindInfo.Identifier),
|
||||
BindInfo.Condition,
|
||||
provider, BindInfo.NonLazy);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RegisterProviderPerContract(
|
||||
DiContainer container, Func<DiContainer, Type, IProvider> providerFunc)
|
||||
{
|
||||
foreach (var contractType in BindInfo.ContractTypes)
|
||||
{
|
||||
var provider = providerFunc(container, contractType);
|
||||
|
||||
if (BindInfo.MarkAsUniqueSingleton)
|
||||
{
|
||||
container.SingletonMarkRegistry.MarkSingleton(contractType);
|
||||
}
|
||||
else if (BindInfo.MarkAsCreationBinding)
|
||||
{
|
||||
container.SingletonMarkRegistry.MarkNonSingleton(contractType);
|
||||
}
|
||||
|
||||
RegisterProvider(container, contractType, provider);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RegisterProviderForAllContracts(
|
||||
DiContainer container, IProvider provider)
|
||||
{
|
||||
foreach (var contractType in BindInfo.ContractTypes)
|
||||
{
|
||||
if (BindInfo.MarkAsUniqueSingleton)
|
||||
{
|
||||
container.SingletonMarkRegistry.MarkSingleton(contractType);
|
||||
}
|
||||
else if (BindInfo.MarkAsCreationBinding)
|
||||
{
|
||||
container.SingletonMarkRegistry.MarkNonSingleton(contractType);
|
||||
}
|
||||
|
||||
RegisterProvider(container, contractType, provider);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RegisterProvidersPerContractAndConcreteType(
|
||||
DiContainer container,
|
||||
List<Type> concreteTypes,
|
||||
Func<Type, Type, IProvider> providerFunc)
|
||||
{
|
||||
Assert.That(!BindInfo.ContractTypes.IsEmpty());
|
||||
Assert.That(!concreteTypes.IsEmpty());
|
||||
|
||||
foreach (var contractType in BindInfo.ContractTypes)
|
||||
{
|
||||
foreach (var concreteType in concreteTypes)
|
||||
{
|
||||
if (ValidateBindTypes(concreteType, contractType))
|
||||
{
|
||||
RegisterProvider(container, contractType, providerFunc(contractType, concreteType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if the bind should continue, false to skip
|
||||
bool ValidateBindTypes(Type concreteType, Type contractType)
|
||||
{
|
||||
bool isConcreteOpenGenericType = concreteType.IsOpenGenericType();
|
||||
bool isContractOpenGenericType = contractType.IsOpenGenericType();
|
||||
if (isConcreteOpenGenericType != isContractOpenGenericType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !(UNITY_WSA && ENABLE_DOTNET)
|
||||
// TODO: Is it possible to do this on WSA?
|
||||
|
||||
if (isContractOpenGenericType)
|
||||
{
|
||||
Assert.That(isConcreteOpenGenericType);
|
||||
|
||||
if (TypeExtensions.IsAssignableToGenericType(concreteType, contractType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (concreteType.DerivesFromOrEqual(contractType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if (concreteType.DerivesFromOrEqual(contractType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (BindInfo.InvalidBindResponse == InvalidBindResponses.Assert)
|
||||
{
|
||||
throw Assert.CreateException(
|
||||
"Expected type '{0}' to derive from or be equal to '{1}'", concreteType, contractType);
|
||||
}
|
||||
|
||||
Assert.IsEqual(BindInfo.InvalidBindResponse, InvalidBindResponses.Skip);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note that if multiple contract types are provided per concrete type,
|
||||
// it will re-use the same provider for each contract type
|
||||
// (each concrete type will have its own provider though)
|
||||
protected void RegisterProvidersForAllContractsPerConcreteType(
|
||||
DiContainer container,
|
||||
List<Type> concreteTypes,
|
||||
Func<DiContainer, Type, IProvider> providerFunc)
|
||||
{
|
||||
Assert.That(!BindInfo.ContractTypes.IsEmpty());
|
||||
Assert.That(!concreteTypes.IsEmpty());
|
||||
|
||||
var providerMap = ZenPools.SpawnDictionary<Type, IProvider>();
|
||||
try
|
||||
{
|
||||
foreach (var concreteType in concreteTypes)
|
||||
{
|
||||
var provider = providerFunc(container, concreteType);
|
||||
|
||||
providerMap[concreteType] = provider;
|
||||
|
||||
if (BindInfo.MarkAsUniqueSingleton)
|
||||
{
|
||||
container.SingletonMarkRegistry.MarkSingleton(concreteType);
|
||||
}
|
||||
else if (BindInfo.MarkAsCreationBinding)
|
||||
{
|
||||
container.SingletonMarkRegistry.MarkNonSingleton(concreteType);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var contractType in BindInfo.ContractTypes)
|
||||
{
|
||||
foreach (var concreteType in concreteTypes)
|
||||
{
|
||||
if (ValidateBindTypes(concreteType, contractType))
|
||||
{
|
||||
RegisterProvider(container, contractType, providerMap[concreteType]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ZenPools.DespawnDictionary(providerMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee5cb643a9ee24c4fa00e62afc9ef599
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class ScopableBindingFinalizer : ProviderBindingFinalizer
|
||||
{
|
||||
readonly Func<DiContainer, Type, IProvider> _providerFactory;
|
||||
|
||||
public ScopableBindingFinalizer(
|
||||
BindInfo bindInfo, Func<DiContainer, Type, IProvider> providerFactory)
|
||||
: base(bindInfo)
|
||||
{
|
||||
_providerFactory = providerFactory;
|
||||
}
|
||||
|
||||
protected override void OnFinalizeBinding(DiContainer container)
|
||||
{
|
||||
if (BindInfo.ToChoice == ToChoices.Self)
|
||||
{
|
||||
Assert.IsEmpty(BindInfo.ToTypes);
|
||||
FinalizeBindingSelf(container);
|
||||
}
|
||||
else
|
||||
{
|
||||
FinalizeBindingConcrete(container, BindInfo.ToTypes);
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingConcrete(DiContainer container, List<Type> concreteTypes)
|
||||
{
|
||||
if (concreteTypes.Count == 0)
|
||||
{
|
||||
// This can be common when using convention based bindings
|
||||
return;
|
||||
}
|
||||
|
||||
var scope = GetScope();
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container, concreteTypes, _providerFactory);
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) =>
|
||||
BindingUtil.CreateCachedProvider(
|
||||
_providerFactory(container, concreteType)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingSelf(DiContainer container)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProviderPerContract(container, _providerFactory);
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) =>
|
||||
BindingUtil.CreateCachedProvider(
|
||||
_providerFactory(container, contractType)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2392181aaeca434cb15e2719d7567d6
|
||||
timeCreated: 1461708053
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SingleProviderBindingFinalizer : ProviderBindingFinalizer
|
||||
{
|
||||
readonly Func<DiContainer, Type, IProvider> _providerFactory;
|
||||
|
||||
public SingleProviderBindingFinalizer(
|
||||
BindInfo bindInfo, Func<DiContainer, Type, IProvider> providerFactory)
|
||||
: base(bindInfo)
|
||||
{
|
||||
_providerFactory = providerFactory;
|
||||
}
|
||||
|
||||
protected override void OnFinalizeBinding(DiContainer container)
|
||||
{
|
||||
if (BindInfo.ToChoice == ToChoices.Self)
|
||||
{
|
||||
Assert.IsEmpty(BindInfo.ToTypes);
|
||||
|
||||
RegisterProviderPerContract(container, _providerFactory);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Empty sometimes when using convention based bindings
|
||||
if (!BindInfo.ToTypes.IsEmpty())
|
||||
{
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container, BindInfo.ToTypes, _providerFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: deaa9a3ee9e42a8448bba948495b9225
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerBindingFinalizer : ProviderBindingFinalizer
|
||||
{
|
||||
readonly object _subIdentifier;
|
||||
readonly bool _resolveAll;
|
||||
readonly Func<DiContainer, ISubContainerCreator> _creatorFactory;
|
||||
|
||||
public SubContainerBindingFinalizer(
|
||||
BindInfo bindInfo, object subIdentifier,
|
||||
bool resolveAll, Func<DiContainer, ISubContainerCreator> creatorFactory)
|
||||
: base(bindInfo)
|
||||
{
|
||||
_subIdentifier = subIdentifier;
|
||||
_resolveAll = resolveAll;
|
||||
_creatorFactory = creatorFactory;
|
||||
}
|
||||
|
||||
protected override void OnFinalizeBinding(DiContainer container)
|
||||
{
|
||||
if (BindInfo.ToChoice == ToChoices.Self)
|
||||
{
|
||||
Assert.IsEmpty(BindInfo.ToTypes);
|
||||
FinalizeBindingSelf(container);
|
||||
}
|
||||
else
|
||||
{
|
||||
FinalizeBindingConcrete(container, BindInfo.ToTypes);
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingConcrete(DiContainer container, List<Type> concreteTypes)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) =>
|
||||
new SubContainerDependencyProvider(
|
||||
concreteType, _subIdentifier, _creatorFactory(container), _resolveAll));
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
var containerCreator = new SubContainerCreatorCached(_creatorFactory(container));
|
||||
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) =>
|
||||
new SubContainerDependencyProvider(
|
||||
concreteType, _subIdentifier, containerCreator, _resolveAll));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingSelf(DiContainer container)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) => new SubContainerDependencyProvider(
|
||||
contractType, _subIdentifier, _creatorFactory(container), _resolveAll));
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
var containerCreator = new SubContainerCreatorCached(_creatorFactory(container));
|
||||
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) =>
|
||||
new SubContainerDependencyProvider(
|
||||
contractType, _subIdentifier, containerCreator, _resolveAll));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b263fb784fd4b8140b850ff4d68c7aad
|
||||
timeCreated: 1535189470
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
#if !NOT_UNITY3D
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class SubContainerPrefabBindingFinalizer : ProviderBindingFinalizer
|
||||
{
|
||||
readonly object _subIdentifier;
|
||||
readonly bool _resolveAll;
|
||||
readonly Func<DiContainer, ISubContainerCreator> _subContainerCreatorFactory;
|
||||
|
||||
public SubContainerPrefabBindingFinalizer(
|
||||
BindInfo bindInfo,
|
||||
object subIdentifier, bool resolveAll,
|
||||
Func<DiContainer, ISubContainerCreator> subContainerCreatorFactory)
|
||||
: base(bindInfo)
|
||||
{
|
||||
_subIdentifier = subIdentifier;
|
||||
_resolveAll = resolveAll;
|
||||
_subContainerCreatorFactory = subContainerCreatorFactory;
|
||||
}
|
||||
|
||||
protected override void OnFinalizeBinding(DiContainer container)
|
||||
{
|
||||
if (BindInfo.ToChoice == ToChoices.Self)
|
||||
{
|
||||
Assert.IsEmpty(BindInfo.ToTypes);
|
||||
FinalizeBindingSelf(container);
|
||||
}
|
||||
else
|
||||
{
|
||||
FinalizeBindingConcrete(container, BindInfo.ToTypes);
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingConcrete(DiContainer container, List<Type> concreteTypes)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) => new SubContainerDependencyProvider(
|
||||
concreteType, _subIdentifier,
|
||||
_subContainerCreatorFactory(container), _resolveAll));
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
var containerCreator = new SubContainerCreatorCached(
|
||||
_subContainerCreatorFactory(container));
|
||||
|
||||
RegisterProvidersForAllContractsPerConcreteType(
|
||||
container,
|
||||
concreteTypes,
|
||||
(_, concreteType) =>
|
||||
new SubContainerDependencyProvider(
|
||||
concreteType, _subIdentifier, containerCreator, _resolveAll));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FinalizeBindingSelf(DiContainer container)
|
||||
{
|
||||
var scope = GetScope();
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case ScopeTypes.Transient:
|
||||
{
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) => new SubContainerDependencyProvider(
|
||||
contractType, _subIdentifier,
|
||||
_subContainerCreatorFactory(container), _resolveAll));
|
||||
break;
|
||||
}
|
||||
case ScopeTypes.Singleton:
|
||||
{
|
||||
var containerCreator = new SubContainerCreatorCached(
|
||||
_subContainerCreatorFactory(container));
|
||||
|
||||
RegisterProviderPerContract(
|
||||
container,
|
||||
(_, contractType) =>
|
||||
new SubContainerDependencyProvider(
|
||||
contractType, _subIdentifier, containerCreator, _resolveAll));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da4cb0f689a9b074aa3d2f2da8b38015
|
||||
timeCreated: 1461708054
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user