Results 1 to 2 of 2

Thread: When should I not use IoC/DI?

  1. #1
    Join Date
    Mar 2006
    Location
    Honolulu, HI
    Posts
    2

    Default When should I not use IoC/DI?

    I was getting all fired up to use dependency injection with some presentation layer classes, for example, by creating a setLog(Log log) method to inject the class Log (or instead maybe the Log Factory) for each class to use...

    Then I looked at the "Spring How-To" for building an MVC application step-by-step and noted with dismay that the example code is calling:

    Code:
    LogFactory.getLog(getClass());
    Hmmm... No DI there. So my questions are:
    • Is this an overly simple example or are system utilities simply inappropriate for dependency injection?
    • Are some dependencies more appropriate for DI than others?


    I await your philosophical discourse! --Dan

  2. #2

    Default

    Dan,

    If you want a "philosophical" discourse to this, then logging is a cross-cutting concern, and you should handle it via AOP! Spring offers dynamic proxies for you to be able to achieve this. If you still want finer grained logging then look at AspectJ.

    If you want a more practical approach, then well, you can go with either of the methods you've described above. Let's face it, as long as you have abstracted your logging out by DI or behind a LogFactory, you can change the implementation (if you ever need to - I've never changed logging implementations really).
    Thanks, Karthik

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •