DI and cross-cutting concerns

Just came across some great guidance from Casey Charlton on the ALT.NET mailing list. My last post on dependency injection mentioned the benefit of documenting class dependencies via the constructor used for DI. But what about cross cutting concerns like logging? From Casey’s mailing list post:

"Constructor properties shouldnt be used for cross cutting concerns like logging … Put ILogger as a public property on the class, use the nulllogger as the default value, register the logging facility in Windsor, and all will magically happen"

I like this – unique dependencies in your constructor, others set via property-injection. I’m also pretty keen on the idea of AOP for doing a lot of basic logging, but I haven’t had a good look at this in .NET yet. The ALT.NET thread has a bit more of a discussion on logging.

Comments