Update readme to match modified assisted injection API

This commit is contained in:
Jakub Stasiak 2012-12-13 22:13:33 +00:00
parent bc8d961b65
commit a595e57112
1 changed files with 4 additions and 8 deletions

View File

@ -290,17 +290,13 @@ to inject objects of class ``User``.
In this situation there's technique called Assisted injection::
>>> UserUpdaterFactory = Key('UserUpdaterFactory')
>>> def module(binder):
... binder.bind(UserUpdaterFactory, to=AssistedFactoryProvider(UserUpdater))
... injector = Injector(module)
... factory = injector.get(UserUpdaterFactory)
... builder = injector.get(AssistedBuilder(UserUpdater))
... user = User('John')
... user_updater = factory.create(user=user)
... user_updater = builder.build(user=user)
This way we don't make ``UserUpdater`` directly injectable - we provide injectable factory.
Such factory has ``create(**kwargs)`` method which takes non-injectable parameters, combines
This way we don't make ``UserUpdater`` directly injectable - we provide injectable builder.
Such builder has ``build(**kwargs)`` method which takes non-injectable parameters, combines
them with injectable dependencies of ``UserUpdater`` and calls ``UserUpdater`` initializer
using all of them.