• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: WebObjects and dependency injection (DI)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WebObjects and dependency injection (DI)


  • Subject: Re: WebObjects and dependency injection (DI)
  • From: Andrus Adamchik <email@hidden>
  • Date: Tue, 22 Sep 2009 11:31:09 +0300


On Sep 22, 2009, at 9:07 AM, Anjo Krank wrote:

My argument being, I have a lot of code that depends on various "services" and their instantiation. But 90% of the time, this code depends on user input, program state and external stuff. It's very rare that I actually know at compile time what implementation I have. We normally use Class.forName().newInstance() in some way or other to handle that. So can DI help me there? If yes, how?

DI is just an environment to help you with your interface-based design. Nothing prevents you from writing a dynamic strategy-based service. At the same time DI it can simplify the public API of your services in many cases by removing environment-specific arguments from your method signatures. E.g.:


ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(ec, model.name());
ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(ec, dbc);
ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(ec, channel);

may become

 ERXSQLHelper sqlHelper = sqlHelperService.newSQLHelper(model.name());
 ERXSQLHelper sqlHelper = sqlHelperService.newSQLHelper(dbc);
 ERXSQLHelper sqlHelper = sqlHelperService.newSQLHelper(channel);

So here you don't need to pass ec to the method as it is injected in sqlHelperService behind the scenes. This means that you don't need to carry over all needed parameters through the call chain, just to pass it down to some method. It creates some really nice refactoring opportunities, and again - it reduces coupling of the public API.

I should say I didn't get DI in theory until I tried it. Just like many programming optimizations (say OO vs. procedural) this is about a better abstraction which is not really obvious until you start using it.

Andrus

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: WebObjects and dependency injection (DI)
      • From: Andrus Adamchik <email@hidden>
References: 
 >WebObjects and dependency injection (DI) (From: Andrus Adamchik <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Henrique Prange <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Andrus Adamchik <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Anjo Krank <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Andrus Adamchik <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Anjo Krank <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Andrew Lindesay <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Anjo Krank <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Henrique Prange <email@hidden>)
 >Re: WebObjects and dependency injection (DI) (From: Anjo Krank <email@hidden>)

  • Prev by Date: Re: Multi-Tenant Data Architecture
  • Next by Date: Re: Proper Wonder/App Initialization for testing
  • Previous by thread: Re: WebObjects and dependency injection (DI)
  • Next by thread: Re: WebObjects and dependency injection (DI)
  • Index(es):
    • Date
    • Thread