Note that there are some explanatory texts on larger screens.

plurals
  1. PONinject Interceptors
    primarykey
    data
    text
    <p>I'm developing a WPF desktop application with caliburn.micro framework, and I want to configure ninject interceptors so that I can intercept method calls. I would like to do this to handle exceptions in a centralized place, so that I don't have many try-catch blocks everywhere around my code.</p> <p>I haven't been able to acomplish this, because everytime I wire everything up with ninject, the system throws an exception.</p> <p>So here's some code:</p> <p>The AppBootstrapper configure method looks like this:</p> <pre><code> protected override void Configure() { _kernel = new StandardKernel(new NinjectServiceModule()); _kernel.Bind&lt;IWindowManager&gt;().To&lt;WindowManager&gt;().InSingletonScope(); _kernel.Bind&lt;IEventAggregator&gt;().To&lt;EventAggregator&gt;().InSingletonScope(); _kernel.Bind&lt;ISomeViewModel&gt;().To&lt;SomeViewModel&gt;().Intercept().With&lt;SomeInterceptor&gt;() //this is where the exception is thrown; _kernel.Bind&lt;IShell&gt;().To&lt;ShellViewModel&gt;(); } </code></pre> <p>Now the intercept method in my interceptor:</p> <pre><code> public void Intercept(IInvocation invocation) { if (invocation.Request.Method.Name == "TheMethodIWantIntercepted") { try { invocation.Proceed(); } catch (Exception) { Console.WriteLine("I Handled exception"); } } else { invocation.Proceed(); } } </code></pre> <p>The method in the view model looks like this:</p> <pre><code> public virtual void TheMethodIWantIntercepted() { //Some logic here } </code></pre> <p>So that's how interceptors are supposed to work. But it doesn't work, everytime I run the program, and ninject tries to inject the instance of SomeViewModel into ISomeViewModel, the program execution fails, and this is the exception that is thrown (and the stack trace): <a href="http://pastebin.com/qerZAjVr" rel="nofollow">http://pastebin.com/qerZAjVr</a></p> <p>Hope you can help me with this, thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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