Initial Commit
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class MemoryPoolBindingFinalizer<TContract> : ProviderBindingFinalizer
|
||||
{
|
||||
readonly MemoryPoolBindInfo _poolBindInfo;
|
||||
readonly FactoryBindInfo _factoryBindInfo;
|
||||
|
||||
public MemoryPoolBindingFinalizer(
|
||||
BindInfo bindInfo, FactoryBindInfo factoryBindInfo, MemoryPoolBindInfo poolBindInfo)
|
||||
: base(bindInfo)
|
||||
{
|
||||
// Note that it doesn't derive from MemoryPool<TContract>
|
||||
// when used with To<>, so we can only check IMemoryPoolBase
|
||||
Assert.That(factoryBindInfo.FactoryType.DerivesFrom<IMemoryPool>());
|
||||
|
||||
_factoryBindInfo = factoryBindInfo;
|
||||
_poolBindInfo = poolBindInfo;
|
||||
}
|
||||
|
||||
protected override void OnFinalizeBinding(DiContainer container)
|
||||
{
|
||||
var factory = new FactoryProviderWrapper<TContract>(
|
||||
_factoryBindInfo.ProviderFunc(container), new InjectContext(container, typeof(TContract)));
|
||||
|
||||
var settings = new MemoryPoolSettings(
|
||||
_poolBindInfo.InitialSize, _poolBindInfo.MaxSize, _poolBindInfo.ExpandMethod);
|
||||
|
||||
var transientProvider = new TransientProvider(
|
||||
_factoryBindInfo.FactoryType,
|
||||
container,
|
||||
_factoryBindInfo.Arguments.Concat(
|
||||
InjectUtil.CreateArgListExplicit(factory, settings)).ToList(),
|
||||
BindInfo.ContextInfo, BindInfo.ConcreteIdentifier, null);
|
||||
|
||||
IProvider mainProvider;
|
||||
|
||||
if (BindInfo.Scope == ScopeTypes.Unset || BindInfo.Scope == ScopeTypes.Singleton)
|
||||
{
|
||||
mainProvider = BindingUtil.CreateCachedProvider(transientProvider);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsEqual(BindInfo.Scope, ScopeTypes.Transient);
|
||||
mainProvider = transientProvider;
|
||||
}
|
||||
|
||||
RegisterProviderForAllContracts(container, mainProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41eb30ac64078db4090dd136ccaf1fbe
|
||||
timeCreated: 1485699960
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class MemoryPoolExpandBinder<TContract> : FactoryArgumentsToChoiceBinder<TContract>
|
||||
{
|
||||
public MemoryPoolExpandBinder(
|
||||
DiContainer bindContainer, BindInfo bindInfo, FactoryBindInfo factoryBindInfo, MemoryPoolBindInfo poolBindInfo)
|
||||
: base(bindContainer, bindInfo, factoryBindInfo)
|
||||
{
|
||||
MemoryPoolBindInfo = poolBindInfo;
|
||||
|
||||
ExpandByOneAtATime();
|
||||
}
|
||||
|
||||
protected MemoryPoolBindInfo MemoryPoolBindInfo
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public FactoryArgumentsToChoiceBinder<TContract> ExpandByOneAtATime()
|
||||
{
|
||||
MemoryPoolBindInfo.ExpandMethod = PoolExpandMethods.OneAtATime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FactoryArgumentsToChoiceBinder<TContract> ExpandByDoubling()
|
||||
{
|
||||
MemoryPoolBindInfo.ExpandMethod = PoolExpandMethods.Double;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95b7c7be81364a740b952460f5a07bbf
|
||||
timeCreated: 1485699961
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class MemoryPoolMaxSizeBinder<TContract> : MemoryPoolExpandBinder<TContract>
|
||||
{
|
||||
public MemoryPoolMaxSizeBinder(
|
||||
DiContainer bindContainer, BindInfo bindInfo, FactoryBindInfo factoryBindInfo, MemoryPoolBindInfo poolBindInfo)
|
||||
: base(bindContainer, bindInfo, factoryBindInfo, poolBindInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public MemoryPoolExpandBinder<TContract> WithMaxSize(int size)
|
||||
{
|
||||
MemoryPoolBindInfo.MaxSize = size;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MemoryPoolInitialSizeMaxSizeBinder<TContract> : MemoryPoolMaxSizeBinder<TContract>
|
||||
{
|
||||
public MemoryPoolInitialSizeMaxSizeBinder(
|
||||
DiContainer bindContainer, BindInfo bindInfo, FactoryBindInfo factoryBindInfo, MemoryPoolBindInfo poolBindInfo)
|
||||
: base(bindContainer, bindInfo, factoryBindInfo, poolBindInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public MemoryPoolMaxSizeBinder<TContract> WithInitialSize(int size)
|
||||
{
|
||||
MemoryPoolBindInfo.InitialSize = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FactoryArgumentsToChoiceBinder<TContract> WithFixedSize(int size)
|
||||
{
|
||||
MemoryPoolBindInfo.InitialSize = size;
|
||||
MemoryPoolBindInfo.MaxSize = size;
|
||||
MemoryPoolBindInfo.ExpandMethod = PoolExpandMethods.Disabled;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class MemoryPoolIdInitialSizeMaxSizeBinder<TContract> : MemoryPoolInitialSizeMaxSizeBinder<TContract>
|
||||
{
|
||||
public MemoryPoolIdInitialSizeMaxSizeBinder(
|
||||
DiContainer bindContainer, BindInfo bindInfo, FactoryBindInfo factoryBindInfo, MemoryPoolBindInfo poolBindInfo)
|
||||
: base(bindContainer, bindInfo, factoryBindInfo, poolBindInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public MemoryPoolInitialSizeMaxSizeBinder<TContract> WithId(object identifier)
|
||||
{
|
||||
BindInfo.Identifier = identifier;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80ff9e6d501d30d4a82639f4ae453712
|
||||
timeCreated: 1485699961
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user