Re: How to I access a logging class from any other class.



ssg31415926 ha scritto:
I want to be able to write log data.  How can I access my logging class
from any class in the app, without passing a reference to it?

SH


Just my $0.02: Try investigate for:

1- Inversion Of Control
2- Dependency Injection
3- Service Locator

About 1 and 2 there's a widely known article from Martin Fowler, as well
as heaps of stuff scattered over the net.

As of now, I'm quite enjoying reading about these subjects, and I think
they could solve your problem.

I understand that Service Locator are containers where you can register
services that client code can use later.

Something like:

myServices.Register(MyFavouriteLoggerType)
myServices.Register(MyApplicationConfigType)
....
....
myMarvelousClient.logger = myServices.getInstanceOf(MyFavouriteLoggerType)
....


Hope that helps.

Regards,
Carmine
.