Service Container and Provider

Main Service Container and Provider.

Sets up the framework and runs the experiments and lets you customize/extend the behavior of the framework.

Binding

We can register/bind a new alias by extending either the register_aliases class() or by directly adding the alias to the aliases dictionary. The key is the alias name you want to register and the value is a function that returns an instance of the class:

def register_aliases(self):
    super(MyAppClass, self).register_aliases()

    self.aliases['my_custom_api'] = lambda: API(self.store)

Additional arguments for creating a class instance may be passed when resolving. Your function just has to add them in order to use them:

self.aliases['my_custom_api'] = lambda name, user_id=None: API(self.store, name, user_id)

Resolving

You may use the make() method to resolve a class instance out of the container. The make() method accepts the alias of the class you want to resolve:

api = self.app.make('my_custom_api')

If some of your class’ dependencies are not resolvable via the app container, you may pass them as additional args and keyword args:

api = self.app.make('my_custom_api', foo, user_id=42)

Customizing

Commands

Register new commands with the App.register_commands() method. It should return a dictionary where the keys are names of the commands and the values are the command handlers. The command handlers must either be derived from AbstractCommand or a function with the decorator AbstractCommand.command(). Example return:

{
    'foo': FooCommand,
    'bar': BarCommand
}