/// <inheritdoc /> /// <summary> /// Remove an <c>IMediator</c> from the <c>View</c>. /// </summary> /// <param name="mediatorName">name of the <c>IMediator</c> instance to be removed.</param> /// <returns>the <c>IMediator</c> that was removed from the <c>View</c></returns> public virtual IMediator RemoveMediator(string mediatorName) { if (!MediatorMap.ContainsKey(mediatorName)) { return(null); } var mediator = MediatorMap[mediatorName]; var interests = mediator.ListNotificationInterests(); foreach (var i in interests) { RemoveObserver(i, mediator); } mediator.OnRemove(); return(mediator); }
/// <inheritdoc /> /// <summary> /// Register an <c>IMediator</c> instance with the <c>View</c>. /// </summary> /// <remarks> /// <para> /// Registers the <c>IMediator</c> so that it can be retrieved by name, /// and further interrogates the <c>IMediator</c> for its /// <c>INotification</c> interests. /// </para> /// <para> /// If the <c>IMediator</c> returns any <c>INotification</c> /// names to be notified about, an <c>Observer</c> is created encapsulating /// the <c>IMediator</c> instance's <c>handleNotification</c> method /// and registering it as an <c>Observer</c> for all <c>INotifications</c> the /// <c>IMediator</c> is interested in. /// </para> /// </remarks> /// <param name="mediator">the name to associate with this <c>IMediator</c> instance</param> public virtual void RegisterMediator(IMediator mediator) { if (MediatorMap.ContainsKey(mediator.MediatorName)) { return; } MediatorMap[mediator.MediatorName] = mediator; var interests = mediator.ListNotificationInterests(); if (interests.Length > 0) { var observer = new Observer(mediator.HandleNotification, mediator); foreach (var i in interests) { RegisterObserver(i, observer); } } // alert the mediator that it has been registered mediator.OnRegister(); }
/// <inheritdoc /> /// <summary> /// Check if a Mediator is registered or not /// </summary> /// <param name="mediatorName"></param> /// <returns>whether a Mediator is registered with the given <c>mediatorName</c>.</returns> public virtual bool HasMediator(string mediatorName) { return(MediatorMap.ContainsKey(mediatorName)); }