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.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • Technorati