Class Dependancy Injection

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


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?

 

Thanks,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070413/466cb614/attachment.html>


More information about the Python-list mailing list