/// Removes a mediator when its hollyView is destroyed protected virtual void unmapActor(IHollywoodView actor, IMediationBinding binding) { var actorType = actor.GetType(); if (bindings.ContainsKey(actorType)) { int length = 0; length = directory[actor].Count; for (var i = 0; i < length; i++) { directory[actor][i].OnRemove(); } } //remove reference to IActor and IDirector instances to allow gc directory[actor].Clear(); directory.Remove(actor); }
/// Creates and registers one or more Director for a specific Actor instance. /// Please note that in this extansion's way of thinking, an Actor has one and only one Director. /// Takes a specific Actor instance and a binding and, if a binding is found for that type, creates and registers a Director. protected virtual void mapView(IHollywoodView hollyView, IMediationBinding binding) { var viewType = hollyView.GetType(); if (bindings.ContainsKey(viewType)) { var values = binding.value as object[]; var aa = values.Length; for (var a = 0; a < aa; a++) { var mono = hollyView as MonoBehaviour; IDirector director = null; if (values[a] is Type) { var directorType = values[a] as Type; if (directorType == viewType) { throw new MediationException( viewType + "mapped to itself. The result would be a stack overflow.", MediationExceptionType.MEDIATOR_VIEW_STACK_OVERFLOW); } IInjectionBinding bindingTest = injectionBinder.GetBinding(directorType, null) as IInjectionBinding; if (bindingTest == null) { //Default use case injectionBinder.Bind <IDirector>().To(directorType); director = injectionBinder.GetInstance <IDirector>(); injectionBinder.Unbind <IDirector>(); } else { //Actor is bind to an Interface... director = injectionBinder.GetInstance(directorType) as IDirector; } } else { //Actor is bind to a concrete object instance director = values[a] as IDirector; } if (director is IDirector) { director.PreRegister(); } var typeToInject = binding.abstraction == null || binding.abstraction.Equals(BindingConst.NULLOID) ? viewType : binding.abstraction as Type; injectionBinder.Bind(typeToInject).ToValue(hollyView).ToInject(false); injectionBinder.injector.Inject(director, false); injectionBinder.Unbind(typeToInject); if (director is IDirector) { director.OnRegister(hollyView as IActor); (hollyView as IActor).Director = director; } registerDirector(hollyView, director); } } }