Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6340163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:47:03+00:00 2026-05-24T19:47:03+00:00

Reading this blog post it mentions you can get your DI container to automatically

  • 0

Reading this blog post it mentions you can get your DI container to automatically subscribe to events if it implements IHandle<>. That is exactly what I’m trying to accomplish.

Here is what I have so far.

container.Register(Component
    .For<MainWindowViewModel>()
    .ImplementedBy<MainWindowViewModel>()
    .LifeStyle.Transient
    .OnCreate((kernel, thisType) => kernel.Resolve<IEventAggregator>().Subscribe(thisType)));

While this code is successfully subscribing MainWindowViewModel to receive published messages, come time to actually receive messages nothing happens. If I manually subscribe all works as expected.

Here is my MainWindowViewModel class.

public class MainWindowViewModel : IHandle<SomeMessage>
{
    private readonly FooViewModel _fooViewModel;
    private readonly IEventAggregator _eventAggregator;

    public MainWindowViewModel(FooViewModel fooViewModel, IEventAggregator eventAggregator)
    {
        _fooViewModel = fooViewModel;
        _eventAggregator = eventAggregator;

        //_eventAggregator.Subscribe(this);

        _fooViewModel.InvokeEvent();
    }

    public void Handle(SomeMessage message)
    {
        Console.WriteLine("Received message with text: {0}", message.Text);
    }
}

How can I tell Windsor to automatically subscribe if any class inherits IHandle<>?

I ended up coming up with this custom facility that subscribes.

public class EventAggregatorFacility : AbstractFacility
{
    protected override void Init()
    {
        Kernel.DependencyResolving += Kernel_DependencyResolving;
    }

    private void Kernel_DependencyResolving(ComponentModel client, DependencyModel model, object dependency)
    {
        if(typeof(IHandle).IsAssignableFrom(client.Implementation))
        {
            var aggregator = Kernel.Resolve<IEventAggregator>();
            aggregator.Subscribe(client.Implementation);
        }
    }
}

Looking at the EventAggregator class provided by Caliburn.Micro I’m able to see that the subcription is successful, however if another class publishes a message the MainWindowViewModel class isn’t getting getting handled. Manually subscribing still works but I’d like to automate this process. I have a feeling that it’s not subscribing the correct instance. Not sure how to fix that, though.

I’ve also tried using every other event exposed by the Kernel property. Most of them can’t resolve IEventAggregator.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:47:04+00:00Added an answer on May 24, 2026 at 7:47 pm

    “I have a feeling that it’s not subscribing the correct instance. Not
    sure how to fix that, though.”

    You are subscribing to the type of the implementation (an instance of System.Type), not the actual dependency being resolved. The line:

    aggregator.Subscribe(client.Implementation);
    

    should be

    aggregator.Subscribe(dependency);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
Should be an easy one. I thought, from reading this blog post that I
Reading this blog post about HttpOnly cookies made me start thinking, is it possible
I've been reading this post on the android developer blog about the twitter client
I was reading a blog post and saw a groovy snippet that looked lik
Reading things like this post on Dan Guzman's blog , I wonder: why isn't
Recently, I've got a dangerous idea into my head after reading this blog post.
I was reading this post on the MySQL performance blog. Under application tuning it
After reading this blog post: http://www.sitepoint.com/javascript-shared-web-workers-html5/ I don't get it. What's the difference between
After reading this blog entry : http://wekeroad.com/post/4069048840/when-should-a-method-be-a-property , I'm wondering why Microsoft choose in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.