Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you are misunderstanding what happens. Your <code>Foo</code> object is replaced with an decorator that contains the interceptor. Here is a simplistic example:</p> <pre><code>public class FooDecorator : Foo { private readonly Foo decorated; public FooDecorator(Foo foo) { this.decorated = foo; } public void ThrowsAnError(object param1, int param2) { // calls the decorated instance with supplied parameters this.decorated.ThrowsAnError(param1, param2); } } </code></pre> <p>In other words, the parameters that are supplied when the resolved Foo is called, will be passed on to the decorated instance.</p> <p>With interception however, this is all a bit more indirect (and slower), but the concept is the same. I must admit that I'm not familiar with Ninject interception, but there is probably a <code>Proceed</code> method on the <code>invocation</code> object. In other words, you should do something like this:</p> <pre><code>Kernel.InterceptReplace&lt;Foo&gt;(foo =&gt; foo.ThrowsAnError(), invocation =&gt; { try { // calls the decorated instance with supplied parameters invocation.Proceed(); } catch (Exception ex) { Kernel.Get&lt;ILogger&gt;().Log(ex); } } ); </code></pre> <p><strong>UPDATE</strong></p> <p>I assume that the first argument of the <code>InterceptReplace&lt;T&gt;</code> method is not an delegate, but an expression tree, such as <code>Expression&lt;Action&lt;T&gt;&gt;</code>. This method is in fact not called, but it is analyzed to find out which method to intercept. In other words, since the method is never called, you can just supply any argument you which. The trick is to let the C# compiler know which method overload (if any) to use. It doesn't matter if you supply rubbish. When both arguments are reference types, this will probably work:</p> <pre><code>Kernel.InterceptReplace&lt;Foo&gt;(foo =&gt; foo.ThrowsAnError(null, null), </code></pre>
 

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