Class Dependancy Injection

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Fri Apr 13 12:38:08 EDT 2007


Thanks Steve that's good to here. I'll give it a shot this evening and if I
have any problems then 'I'll be back';-)

Rawlins

-----Original Message-----
From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org
[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org]
On Behalf Of Steve Holden
Sent: 13 April 2007 17:32
To: python-list at python.org
Subject: Re: Class Dependancy Injection

Robert Rawlins - Think Blue wrote:
> Hey again guys,
> 
>  
> 
> I'm looking to get an answer about dependency injection in python 
> classes, what is the best way to deal with this?
> 
>  
> 
> For instance, in my application I have a configuration bean which 
> contains all the applications configuration information. Now in one of 
> other classes I need access to those configuration settings. What I 
> would have done in my ColdFusion/JAVA type applications is create an 
> instance of the configuration bean, and then pass that in as an argument 
> to the constructor for my other class, then have the other class set 
> that as a 'self' variable. Then from within my class I can access the 
> configuration details like self.config.getName() and it would return the 
> name of the application.
> 
> How is this best handled in python, can I still inject dependencies as a 
> constructor argument like that? If so then is there anything in 
> particular I need to watch out for that may cause me trouble?
> 
That indeed sounds like the best way to proceed. You should find that, 
modulo the language differences, the technique works in just the same 
way. You shouldn't anticipate trouble.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com

-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list