Class Dependancy Injection
Steve Holden
steve at holdenweb.com
Fri Apr 13 12:31:39 EDT 2007
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
More information about the Python-list
mailing list