snake-guice Binder Options
snake-guice provides a simple DSL to wire up an application’s dependencies. The current version implements this with chained method calls like google-guice. An example from one of the unit tests:
binder.bind(ch.Person)\
.with_annotation('evil')\
.to(ch.EvilPerson)\
.in_scope(scopes.CherryPyRequest)
After using this in a couple of trivial apps I am not so sure I like it. Long chains of method calls are usually regarded as a code smell and it just feels strange in Python. As a replacement syntax I was thinking something more like:
binder.bind(ch.Person,
annotated_with='evil',
to=ch.EvilPerson,
in_scope=scopes.CherryPyRequest)
The new syntax does feel better, but I still feel that something is missing. Either way I like the fact that both examples are in Python. That is a pretty strong requirement here.
ANN: snake-guice Preview - A Dependency Injection Framework
snake-guice is a dependency injection framework for Python. It has been heavily inspired by google-guice.
snake-guice is still in development and will not be ready to be used in production environments for a few weeks. I’m putting this out there in hopes of getting constructive feedback. Unfortunately the documentation is non-existent so the best place to understand how to use snake-guice is from the unit tests. The API tests are the best examples.
If you don’t already know about dependency injection or how it helps then this project may not be for you just yet.
More to come…








