/// <summary> /// Activates the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="reference">The reference.</param> public override void Activate(IContext context, InstanceReference reference) { var messageBroker = context.Kernel.Components.Get <IMessageBroker>(); List <PublicationDirective> publications = context.Plan.GetAll <PublicationDirective>().ToList(); // I don't think this is needed in Ninject2 //if (publications.Count > 0) // context.ShouldTrackInstance = true; foreach (PublicationDirective publication in publications) { IMessageChannel channel = messageBroker.GetChannel(publication.Channel); channel.AddPublication(reference.Instance, publication.Event); } List <SubscriptionDirective> subscriptions = context.Plan.GetAll <SubscriptionDirective>().ToList(); // I don't think this is needed in Ninject2 //if (subscriptions.Count > 0) // context.ShouldTrackInstance = true; foreach (SubscriptionDirective subscription in subscriptions) { IMessageChannel channel = messageBroker.GetChannel(subscription.Channel); channel.AddSubscription(reference.Instance, subscription.Injector, subscription.Thread); } }
/*----------------------------------------------------------------------------------------*/ /// <summary> /// Executed after the instance is initialized. /// </summary> /// <param name="context">The activation context.</param> /// <returns>A value indicating whether to proceed or stop the execution of the strategy chain.</returns> public override StrategyResult AfterInitialize(IContext context) { var messageBroker = context.Binding.Components.Get <IMessageBroker>(); IList <PublicationDirective> publications = context.Plan.Directives.GetAll <PublicationDirective>(); if (publications.Count > 0) { context.ShouldTrackInstance = true; } foreach (PublicationDirective publication in publications) { IMessageChannel channel = messageBroker.GetChannel(publication.Channel); channel.AddPublication(context.Instance, publication.Event); } IList <SubscriptionDirective> subscriptions = context.Plan.Directives.GetAll <SubscriptionDirective>(); if (subscriptions.Count > 0) { context.ShouldTrackInstance = true; } foreach (SubscriptionDirective subscription in subscriptions) { IMessageChannel channel = messageBroker.GetChannel(subscription.Channel); channel.AddSubscription(context.Instance, subscription.Injector, subscription.Thread); } return(StrategyResult.Proceed); }
/// <summary> /// Contributes to the activation of the instance in the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="reference">The instance to process.</param> public override void Activate(IContext context, InstanceReference reference) { var messageBroker = context.Kernel.Components.Get <IWeakEventMessageBroker>(); List <PublicationDirective> publications = context.Plan.GetAll <PublicationDirective>().ToList(); foreach (PublicationDirective publication in publications) { IMessageChannel channel = messageBroker.GetChannel(publication.Channel); channel.AddPublication(reference.Instance, publication.Event); } List <SubscriptionDirective> subscriptions = context.Plan.GetAll <SubscriptionDirective>().ToList(); foreach (SubscriptionDirective subscription in subscriptions) { IMessageChannel channel = messageBroker.GetChannel(subscription.Channel); channel.AddSubscription(reference.Instance, subscription.MethodInfo, subscription.Thread); } }