简体   繁体   English

用Unity注入System.Diagnostics.Trace

[英]Injecting System.Diagnostics.Trace with Unity

I need to inject a TraceSource in my application as a Dependancy Injection. 我需要在我的应用程序中注入TraceSource作为依赖注入。 How can I achieve to do that since TraceSource does not implements any interface? 由于TraceSource没有实现任何接口,我该如何实现?

Wrap an instance of the TraceSource class in another class that does implement an Interface. 将TraceSource类的实例包装在另一个实现接口的类中。 Delegate all calls to the wrapper to the real TraceSource. 将对包装程序的所有调用委托给真实的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. 使用包装器可以获得的一个小好处是,您可以将日志交换到另一个库,这有时发生在团队中有新开发人员或替换了团队而他们更喜欢另一种情况下。记录器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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