using System; using ModestTree; namespace Zenject { [NoReflectionBaking] public class InstantiateCallbackConditionCopyNonLazyBinder : ConditionCopyNonLazyBinder { public InstantiateCallbackConditionCopyNonLazyBinder(BindInfo bindInfo) : base(bindInfo) { } public ConditionCopyNonLazyBinder OnInstantiated( Action callback) { BindInfo.InstantiatedCallback = callback; return this; } public ConditionCopyNonLazyBinder OnInstantiated( Action callback) { // Can't do this here because of factory bindings //Assert.That(BindInfo.ContractTypes.All(x => x.DerivesFromOrEqual())); BindInfo.InstantiatedCallback = (ctx, obj) => { Assert.That(obj == null || obj is T, "Invalid generic argument to OnInstantiated! {0} must be type {1}", obj.GetType(), typeof(T)); callback(ctx, (T)obj); }; return this; } } }