using System; using System.Collections.Generic; using ModestTree; namespace Zenject { [NoReflectionBaking] public class MethodProvider : IProvider { readonly DiContainer _container; readonly Func _method; public MethodProvider( Func 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 args, out Action injectAction, List 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)); } } } }