Note that there are some explanatory texts on larger screens.

plurals
  1. POUnity / EntLib: Injecting a dependency into a CustomTraceListener
    text
    copied!<p>Sorry, this is quite a special topic so this may not be of interest to many. :-(</p> <p>However, I need to do the following thing:</p> <ul> <li><p>I have an application that provides logging to some kind of console window (it's a WPF window, because of application requirements and because the application needs to look flashy even here - our special customer asked for that and talks about it every time we meet)</p></li> <li><p>To provide thread - agnostic logging I created an interface / implementation pair "IGUIController" / "GUIController"</p></li> </ul> <p>So far, so good. It's all fine.</p> <p>However:</p> <ul> <li>I need my own custom trace listener (I call it "GUITraceListener") which uses the IGUIController - interface to write specific log messages to that flashy WPF - window</li> </ul> <p>So far, my solution is to have a hacked, old skool code smell singleton - style "Current" - property on my GUIController (yes, and I'm ashamed, and I DO know that this is terrible) which I invoke like this:</p> <pre><code>GUIController.Current.Log(message); </code></pre> <p>Obviously, this is a no - go.</p> <p>So, the correct way to do that would be to inject the dependency (of course). However, when I do that, I get the complaint (runtime), that I don't provide a constructor with 0 (zero) arguments for my GUITraceListener - class.</p> <p>As a matter of fact, I get that here:</p> <pre><code>EnterpriseLibraryContainer.ConfigureContainer(configurator, ConfigurationSourceFactory.Create()); </code></pre> <p>And the complaint is:</p> <p>ArgumentException was unhandled Unable to find appropriate 0 argument constructor for GUITraceListener</p> <p>This is really bad. I mean, Unity is part of the Enterprise Library, why didn't those guys simply add the possibility of injecting my dependencies?</p> <p>Clarification:</p> <p>What I want to have in the end is:</p> <pre><code> /// &lt;summary&gt; /// Constructor /// &lt;/summary&gt; /// &lt;param name="guiController"&gt;&lt;/param&gt; public GUITraceListener(IGUIController guiController) { // Store the dependencies this.m_GUIController = guiController; } </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