Injecting System.Diagnostics.Trace with Unity

409 Views Asked by At

I need to inject a TraceSource in my application as a Dependancy Injection. How can I achieve to do that since TraceSource does not implements any interface?

1

There are 1 best solutions below

0
MatthewMartin On BEST ANSWER

Wrap an instance of the TraceSource class in another class that does implement an Interface. Delegate all calls to the wrapper to the real TraceSource.

I don't see any other way to do this with unity. The small benefit you'd get with a wrapper is you'd have a point where you could swap out logging to a different library, which sometimes happens when there are new developers on the team or who have replaced the team and they prefer a different logger.