I am using Umbraco 7.1.1 with an MVC project, and I've configured it to use dependency injection (Castle.Windsor in my case). I'm also using NServiceBus to send messages etc and it's working pretty well.
I am now attempting to hook into the ContentService Published event - to try and publish an NServiceBus event to alert other services that the content has changed. What I would like to do is something like this:
public class ContentPublishedEventHandler : ApplicationEventHandler
{
public IBus Bus { get; set; }
public ContentPublishedEventHandler()
{
ContentService.Published += ContentServiceOnPublished;
}
private void ContentServiceOnPublished(IPublishingStrategy sender, PublishEventArgs<IContent> publishEventArgs)
{
Bus.Publish<ContentUpdatedEvent>(e =>
{
e.UpdatedNodeIds = publishEventArgs.PublishedEntities.Select(c => c.Id);
});
}
}
But in this case, Bus
is null as my dependency injection framework is either not configured properly, or (as I suspect), never invoked.
I can get it to work if I rely on a static reference to the bus, but I'd prefer to avoid that if I can. Is what I'm trying to do possible? Ie use dependency injection with these Umbraco events? If so, what configuration do I need to tell Umbraco to use Castle.Windsor to create my event handler?