简体   繁体   中英

Injecting System.Diagnostics.Trace with Unity

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM