Note that there are some explanatory texts on larger screens.

plurals
  1. POCaliburn Micro Constructor Injection Failed
    primarykey
    data
    text
    <p>I am learning Caliburn Micro and try to make use of the <code>EventAggregator</code> from the <a href="http://caliburnmicro.codeplex.com/wikipage?title=The%20Event%20Aggregator" rel="nofollow noreferrer">official site</a>. </p> <p>However, I got an exception </p> <blockquote> <p>"No parameterless constructor defined for this object."</p> </blockquote> <p>The message itself is clear but the example doesn't include a parameterless constructor either. If i add one, the constructor with parameter is not hit and the <code>IEventAggregator</code> is still not injected correctly.</p> <p>Here is my publisher VM after adding the parameterless constructor (without it, exception will be thrown):</p> <pre><code> public MainViewModel() { } public MainViewModel(IEventAggregator ea) : this() { eventAggregator = ea; } </code></pre> <p>And here is the bootstrapper i am using:</p> <pre><code>public class AppBootstrapper : Bootstrapper&lt;MainViewModel&gt; { private readonly SimpleContainer container = new SimpleContainer(); protected override void Configure() { container.Singleton&lt;IEventAggregator, EventAggregator&gt;(); } } </code></pre> <p>Here is the example from CM:</p> <pre><code>// Creating the EventAggregator as a singleton. public class Bootstrapper : BootstrapperBase { private readonly SimpleContainer _container = new SimpleContainer(); // ... Other Bootstrapper Config protected override void Configure(){ _container.Singleton&lt;IEventAggregator, EventAggregator&gt;(); } // ... Other Bootstrapper Config } // Acquiring the EventAggregator in a viewModel. public class FooViewModel { private readonly IEventAggregator _eventAggregator; public FooViewModel(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; } } </code></pre> <p>I checked this post (<a href="https://stackoverflow.com/questions/17372268/inject-eventaggregator-into-viewmodel-with-caliburn-micro">Inject EventAggregator into ViewModel with Caliburn Micro</a>) but it simply said nothing why the CM do not invoke the constructor with injection.</p> <p>I also checked the CM's sample solution but it uses MEF as the DI solution.</p> <p>What do I miss?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload