JammingJ

I have a logging component that I will access in other assemblies. So it was brought up to my attention that I should pass an instance around to these components instead of just making the logging class static. If I make it static I wouldn't need to pass an instance around. What is your take on this

Re: Visual C# General Logging Class - Instance or Static

Peter Ritchie

By requiring other classes to contain an instance of your class you're overlapping concerns and coupling the two classes too much.

I would also question these logging classes, given that there is already a means of accomplishing this through the systems Trace class. It also uses static to separate the concerns.






Re: Visual C# General Logging Class - Instance or Static

Lowendahl

I would argue that the coupling is much harder if you call a static method on a class then it is if you use IoC and inject the dependecy from the outside.

Using a static class, the dependecy is also static, while if you let the logging class implement an interface and pass an instance of a class that implements that interface to the object using it, you have effectively decoupled the implementation and there for separated the concern.

Martin Fowler has written a really good article on decoupling with IoC: http://www.martinfowler.com/articles/injection.html