I have a custom trace listener, with a simple constructor;
public MyTraceListener(ISomething something)
{
_something = something;
}
This is wired to my web app through system.diagnostics in the web.config.. However, it never seems to fire this. How do I get unity to resolve this? Do I need to edit my web.config somehow? If I add a default constructor that fires, so would the correct approach be to have the default constructor do some sort of resolve on itself?
Unfortunately, you’re kind of stuck. The tracing system doesn’t give you the opportunity to take over object creation, so Unity doesn’t get a chance to do constructor injection. The system will new up the trace listener.
The best you can do is to set your dependencies as properties, rather than constructor dependencies, and then grab the trace listener object after it’s been created and call container.BuildUp on it to get properties injected.