Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在我的应用程序中注入一个 TraceSource 作为依赖注入。由于 TraceSource 没有实现任何接口,我该如何做到这一点?
将 TraceSource 类的实例包装在另一个实现接口的类中。将对包装器的所有调用委托给真正的 TraceSource。
我看不出有任何其他方法可以团结一致地做到这一点。使用包装器的一个小好处是,您可以将日志交换到不同的库,这有时会发生在团队中有新开发人员或更换团队并且他们更喜欢不同的库时记录器。