micro.di¶
A light weight Dependency Injection module for asyncio applications.
Getting started¶
Full featured example with component declaration, dependency declaration and initialization of object with dependecies -
import asyncio from micro import di class ShinyComponent(metaclass=di.Component): @asyncio.coroutine def start(self): yield from asyncio.sleep(0) self.spam = 'Ham, eggs, sausage and bacon.' @di.has_deps class HasDependencies: dep = di.Dep(ShinyComponent, 'a_shiny_component') if __name__ == '__main__': di.provide('a_shiny_component', ShinyComponent()) asyncio.get_event_loop().run_until_complete(di.init_components()) has_deps = HasDependencies() assert has_deps.dep.spam == 'Ham, eggs, sausage and bacon.'
Just save it as hello.py (or something similar) and run it with your Python interpreter.
Justification:¶
There’s an internal blog post with more detail and real world examples here: <https://extranet.atlassian.com/display/~dmankin/2015/07/14/micro.di>
TODO(dmankin): port that into .rst format and include here.