public void FinalizeBinding(DiContainer container) { if (BindInfo.ContractTypes.IsEmpty()) { // 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; } OnFinalizeBinding(container); if (BindInfo.NonLazy) { // Note that we can't simply use container.BindRootResolve here because // binding finalizers must only use RegisterProvider to allow cloning / bind // inheritance to work properly var bindingId = new BindingId( typeof(object), DiContainer.DependencyRootIdentifier); foreach (var contractType in BindInfo.ContractTypes) { container.RegisterProvider( bindingId, null, new ResolveProvider( contractType, container, BindInfo.Identifier, false)); } } }
void Construct(SignalManager manager, SignalSettings settings, BindInfo bindInfo) { _manager = manager; SignalId = new BindingId(this.GetType(), bindInfo.Identifier); Settings = settings; }
public InstanceMethodSignalHandler( BindingId signalId, SignalManager manager, InjectContext lookupContext, Func<THandler, Action> methodGetter) : base(signalId, manager, lookupContext) { _methodGetter = methodGetter; }
public StaticMethodWithInstanceSignalHandler( BindingId signalId, SignalManager manager, InjectContext lookupContext, Action <THandler> method) : base(signalId, manager, lookupContext) { _method = method; }
public InstanceMethodSignalHandler( BindingId signalId, SignalManager manager, Lazy <THandler> handler, Func <THandler, Action> methodGetter) : base(signalId, manager, handler) { _methodGetter = methodGetter; }
public InstanceMethodSignalHandlerBase( BindingId signalId, SignalManager manager, Lazy <THandler> handler) : base(signalId, manager) { _handler = handler; }
public InstanceMethodSignalHandlerBase( BindingId signalId, SignalManager manager, InjectContext lookupContext) : base(signalId, manager) { Assert.IsEqual(lookupContext.MemberType, typeof(THandler)); _lookupContext = lookupContext; }
List <ComponentInfo> GetBoundInfosWithId(BindingId bindingId) { List <ComponentInfo> result; if (!_bindings.TryGetValue(bindingId, out result)) { result = new List <ComponentInfo>(); } return(result); }
public void OnSpawned( Action <object> callback, SignalDeclaration declaration) { Assert.IsNull(_callback); _callback = callback; _declaration = declaration; // Cache this in case OnDeclarationDespawned is called _signalId = declaration.BindingId; declaration.Add(this); }
public SignalDeclaration( SignalDeclarationBindInfo bindInfo, [InjectOptional] ZenjectSettings zenjectSettings) { zenjectSettings = zenjectSettings ?? ZenjectSettings.Default; _settings = zenjectSettings.Signals ?? ZenjectSettings.SignalSettings.Default; _bindingId = new BindingId(bindInfo.SignalType, bindInfo.Identifier); _missingHandlerResponses = bindInfo.MissingHandlerResponse; _isAsync = bindInfo.RunAsync; TickPriority = bindInfo.TickPriority; }
private List <ISignalHandler> GetList(BindingId signalType) { List <ISignalHandler> handlers; if (!_signalHandlers.TryGetValue(signalType, out handlers)) { handlers = new List <ISignalHandler>(); _signalHandlers.Add(signalType, handlers); } return(handlers); }
public InjectContext( DiContainer container, Type memberType, string identifier, bool optional, Type objectType, object objectInstance, string memberName, InjectContext parentContext) { ObjectType = objectType; ObjectInstance = objectInstance; Identifier = identifier; MemberName = memberName; MemberType = memberType; Optional = optional; Container = container; BindingId = new BindingId(memberType, identifier); ParentContext = parentContext; }
public InjectContext( DiContainer container, Type memberType, string identifier, bool optional, Type parentType, object parentInstance, string memberName, List <Type> parentTypes) { ParentType = parentType; ParentInstance = parentInstance; Identifier = identifier; MemberName = memberName; MemberType = memberType; ParentTypes = parentTypes; Optional = optional; Container = container; BindingId = new BindingId(memberType, identifier); }
SignalDeclaration GetDeclaration(BindingId signalId) { SignalDeclaration handler; if (_localDeclarationMap.TryGetValue(signalId, out handler)) { return(handler); } if (_parentBus != null) { return(_parentBus.GetDeclaration(signalId)); } return(null); }
internal IEnumerable <ProviderBase> GetProvidersForContract(BindingId bindingId) { List <ProviderBase> providers; if (_providers.TryGetValue(bindingId, out providers)) { return(providers); } // If we are asking for a List<int>, we should also match for any providers that are bound to the open generic type List<> // Currently it only matches one and not the other - not totally sure if this is better than returning both if (bindingId.Type.IsGenericType && _providers.TryGetValue(new BindingId(bindingId.Type.GetGenericTypeDefinition(), bindingId.Identifier), out providers)) { return(providers); } return(Enumerable.Empty <ProviderBase>()); }
void InstallSingleBinding(Type type, string identifier, ComponentInfo componentInfo) { var bindingId = new BindingId(type, identifier); List <ComponentInfo> infoList; if (!_bindings.TryGetValue(bindingId, out infoList)) { infoList = new List <ComponentInfo>(); _bindings.Add(bindingId, infoList); // Note: We only want to register for each unique BindingId once // since we return multiple matches in GetAllInstancesWithInjectSplit _container.RegisterProvider(bindingId, null, this); } infoList.Add(componentInfo); }
public InjectContext( DiContainer container, Type memberType, string identifier, bool optional, Type objectType, object objectInstance, string memberName, InjectContext parentContext, string concreteIdentifier, object fallBackValue, InjectSources sourceType) { ObjectType = objectType; ObjectInstance = objectInstance; Identifier = identifier; ConcreteIdentifier = concreteIdentifier; MemberName = memberName; MemberType = memberType; Optional = optional; FallBackValue = fallBackValue; Container = container; BindingId = new BindingId(memberType, identifier); ParentContext = parentContext; SourceType = sourceType; }
// Returns true the signal was handled public bool Trigger(BindingId signalType, object[] args) { var handlers = GetList(signalType); if (handlers.Count == 0) { return(false); } #if UNITY_EDITOR && ZEN_PROFILING_ENABLED using (ProfileBlock.Start("Signal '{0}'", signalType)) #endif { foreach (var handler in handlers) { handler.Execute(args); } } return(true); }
SignalDeclaration GetDeclaration(BindingId signalId, bool requireDeclaration) { SignalDeclaration handler; if (_localDeclarationMap.TryGetValue(signalId, out handler)) { return(handler); } if (_parentBus != null) { return(_parentBus.GetDeclaration(signalId, requireDeclaration)); } if (requireDeclaration) { throw Assert.CreateException("Fired undeclared signal '{0}'!", signalId); } return(null); }
// Returns true the signal was handled public bool Trigger(BindingId signalType, object[] args) { var handlers = GetList(signalType); if (handlers.IsEmpty()) { return(false); } #if UNITY_EDITOR using (ProfileBlock.Start("Signal '{0}'", signalType)) #endif { foreach (var handler in handlers) { handler.Execute(args); } } return(true); }
public void RegisterProvider( ProviderBase provider, BindingId bindingId) { if (_providers.ContainsKey(bindingId)) { // Prevent duplicate singleton bindings: if (_providers[bindingId].Find(item => ReferenceEquals(item, provider)) != null) { throw new ZenjectBindException( "Found duplicate singleton binding for contract '{0}' and id '{1}'".Fmt(bindingId.Type, bindingId.Identifier)); } _providers[bindingId].Add(provider); } else { _providers.Add(bindingId, new List <ProviderBase> { provider }); } }
public bool Unbind <TContract>(string identifier) { List <ProviderBase> providersToRemove; var bindingId = new BindingId(typeof(TContract), identifier); if (_providers.TryGetValue(bindingId, out providersToRemove)) { _providers.Remove(bindingId); // Only dispose if the provider is not bound to another type foreach (var provider in providersToRemove) { if (_providers.Where(x => x.Value.Contains(provider)).IsEmpty()) { provider.Dispose(); } } return(true); } return(false); }
private void InternalFire(Type signalType, object signal, object identifier, bool requireDeclaration) { var signalId = new BindingId(signalType, identifier); // Do this before creating the signal so that it throws if the signal was not declared var declaration = GetDeclaration(signalId); if (declaration == null) { if (requireDeclaration) { throw Assert.CreateException("Fired undeclared signal '{0}'!", signalId); } } else { if (signal == null) { signal = Activator.CreateInstance(signalType); } declaration.Fire(signal); } }
public void Unregister(BindingId signalType, ISignalHandler handler) { GetList(signalType).RemoveWithConfirm(handler); }
void SetDefaults() { _callback = null; _declaration = null; _signalId = new BindingId(); }
public SignalHandlerBase( BindingId signalId, SignalManager manager) { _manager = manager; _signalId = signalId; }
public bool IsSignalDeclared(Type signalType, object identifier) { var signalId = new BindingId(signalType, identifier); return(GetDeclaration(signalId) != null); }
public StaticMethodSignalHandler( BindingId signalId, SignalManager manager, Action method) : base(signalId, manager) { _method = method; }
void UnsubscribeInternal(BindingId signalId, object token, bool throwIfMissing) { UnsubscribeInternal( new SignalSubscriptionId(signalId, token), throwIfMissing); }
void SubscribeInternal(BindingId signalId, object token, Action <object> callback) { SubscribeInternal( new SignalSubscriptionId(signalId, token), callback); }