Lagom, a type based dependency injection container
Project description
Lagom - Dependency injection container
What
Lagom is a dependency injection container designed to give you "just enough" help with building your dependencies. The intention is that almost all of your code doesn't know about or rely on lagom. Lagom will only be involved at the top level to pull everything together.
Features
- Typed based auto wiring with zero configuration.
- Fully based on types. Strong integration with mypy.
- Minimal changes to existing code.
- Integration with a few common web frameworks.
- Support for async python.
- Thread-safe at runtime
You can see a comparison to other frameworks here
Installation
pip install lagom
# or:
# pipenv install lagom
# poetry add lagom
Usage
Everything in Lagom is based on types. To create an object you pass the type to the container:
container = Container()
some_thing = container[SomeClass]
You can tell the container that something should be a singleton:
container[SomeExpensiveToCreateClass] = SomeExpensiveToCreateClass("up", "left")
You can explicitly tell the container how to construct something by giving it a function:
container[SomeClass] = lambda: SomeClass("down", "spiral")
All of this is done without modifying any of your classes. This is one of the design goals of lagom.
A decorator is provided to hook top level functions into the container.
@bind_to_container(container)
def handle_move_post_request(request: typing.Dict, game: Game = lagom.injectable):
# do something to the game
return Response()
Contributing
Contributions are very welcome. Please see instructions here
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lagom-1.0.0b3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e51d2f97528c7ec035a621d2713c01dc15a613250eede1d5803fd99314615e4 |
|
MD5 | 92d5ba721b1190a6d6280311f70d587e |
|
BLAKE2b-256 | ec1841afa2f22118ce59b430b1f49dd1b816c88f246753ce7c4b8246889b33cd |