Initial Commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[ZenjectAllowDuringValidation]
|
||||
[NoReflectionBaking]
|
||||
public class LazyInject<T> : IValidatable
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly InjectContext _context;
|
||||
|
||||
bool _hasValue;
|
||||
T _value;
|
||||
|
||||
public LazyInject(DiContainer container, InjectContext context)
|
||||
{
|
||||
Assert.DerivesFromOrEqual<T>(context.MemberType);
|
||||
|
||||
_container = container;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
void IValidatable.Validate()
|
||||
{
|
||||
_container.Resolve(_context);
|
||||
}
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_hasValue)
|
||||
{
|
||||
_value = (T)_container.Resolve(_context);
|
||||
_hasValue = true;
|
||||
}
|
||||
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user