Should logging infrastructure be injected when using IoC/DI if logging facade is used?

前端 未结 5 480
栀梦
栀梦 2021-02-02 07:30

I am using Autofac as my IoC and from everything I have read on topic of DI teaches to use \"constructor injection\" to explicitly expose class dependencies... However, I am als

5条回答
  •  既然无缘
    2021-02-02 08:01

    Now, in every class in which I want to do some logging I have extra constructor parameter

    If you need logging many classes in your system, there is something wrong in your design. Either you log too much or you're violating the Single Responsibility Principle, since logging is a cross-cutting concern, and you should not clutter your classes with cross-cutting concerns like logging.

    I answered a (totally different) question a half year back, and my answer is applicable to your question. Please read this.

提交回复
热议问题