Sunday, December 21, 2008

Snake Guice

So I was looking at making my own IoC container in python using inspiration from Ayende's post on rolling your own IoC in a pinch (though I may run into this again when I start playing with ruby) and I came up what I thought would be an ingenious idea to use decorators on methods and classes to do type resolution.
Something like so:

class Foo(object):

@ioc(booable = ghost, mooable = cow)
def __init__(self, booable, moooable): = boo
self.moo = moo

I'm sure it wouldn't be popular with your average python dev, but I again really want autowiring of dependencies, and didn't want to make a bunch of factory classes to tie together a bunch of related dependency chains.

Well someone already went with that idea with snake-guice an IoC container inspiried by google guice which is written in java and makes heavy use of annotations the python equivalent of decorators and not concidentally my inspiration for my attempt at an IoC container.

I'll update with more information later as I get to play with snake-guice if I can grok the concepts and code, perhaps I'll dare venture into OSS and see if I can help contribute.


David Stanek said...

Have you had a chance to play with snake-guice at all? Currently the docs are virtually non-existent, but that should change in the next few weeks.

I would love to have another contributor! Feel free to contact me and/or join the snake-guice Google Group.

Ryan Svihla said...


I actually did get to play with it awhile back, and it worked well. But I had a desire to configure things with a fluent interface in one location away from the rest of my code.

I did use your work as my inspiration (as well as my usage of Castle Windsor) and created

Regardless I'm more than happy to help out where I can with another IoC container. I'm quite certain Pinsor is far from perfect.

Ryan Svihla said...

Looks like i missed this on your blog:


I'll dive in again tonight see if I can find other tidbits.