Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I inject an object into an WCF IErrorHandler implementation with Castle Windsor?
    text
    copied!<p>I'm developing a set of services using WCF. The application is doing dependency injection with Castle Windsor. I've added an <code>IErrorHandler</code> implementation that is added to services via an attribute. Everything is working thus far. The <code>IErrorHandler</code> object (of a class called <code>FaultHandler</code> is being applied properly and invoked.</p> <p>Now I'm adding logging. Castle Windsor is set up to inject the logger object (an instance of <code>IOurLogger</code>). This is working. But when I try to add it to <code>FaultHandler</code> my logger is null.</p> <p>The code for <code>FaultHandler</code> looks something like this:</p> <pre><code>class FaultHandler : IErrorHandler { public IOurLogger logger { get; set; } public bool HandleError(Exception error) { logger.Write("Exception type {0}. Message: {1}", error.GetType(), error.Message); // Let WCF handle things its way. We only want to log. return false; } public void ProvideFault(Exception error, MessageVersion version, Message fault) { } } </code></pre> <p>This throws it's own exception, since <code>logger</code> is null when <code>HandleError()</code> is called.</p> <p>The logger is being successfully injected into the service itself and is usable there, but for some reason I can't use it in <code>FaultHandler</code>.</p> <p><strong>Update</strong>: Here is the relevant part of the Windsor configuration file (edited to protect the innocent):</p> <pre><code>&lt;configuration&gt; &lt;components&gt; &lt;component id="Logger" service="Our.Namespace.IOurLogger, Our.Namespace" type="Our.Namespace.OurLogger, Our.Namespace" /&gt; &lt;/components&gt; &lt;/configuration&gt; </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