Another simple ioc framework for python
Project description
anyioc
Another simple ioc framework for python.
Usage
from anyioc import ServiceProvider
provider = ServiceProvider()
provider.register_singleton('the key', lambda ioc: 102) # ioc will be a `IServiceProvider`
value = provider.get('the key')
assert value == 102
Register and resolve
By default, you can use following methods to register services:
ServiceProvider.register_singleton(key, factory)
ServiceProvider.register_scoped(key, factory)
ServiceProvider.register_transient(key, factory)
ServiceProvider.register(key, factory, lifetime)
ServiceProvider.register_value(key, value)
ServiceProvider.register_group(key, keys)
ServiceProvider.register_bind(new_key, target_key)
And use following methods to resolve services:
ServiceProvider.__getitem__(key)
ServiceProvider.get(key)
ServiceProvider.get_many(key)
get
return None
if the service was not found, but __getitem__
will raise a ServiceNotFoundError
.
Read full documentation.
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
anyioc-0.15.0.tar.gz
(13.9 kB
view details)
Built Distribution
anyioc-0.15.0-py3-none-any.whl
(18.5 kB
view details)
File details
Details for the file anyioc-0.15.0.tar.gz
.
File metadata
- Download URL: anyioc-0.15.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.7 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 644ed60a221d30e835fb75897180c9c90b4eb0fc5c8d8586026ac95e7f4b7624 |
|
MD5 | 34a10a0b4ce046d94f397702e0e5712a |
|
BLAKE2b-256 | c520839c0b651df9e4dec0d5dd0c591a9a2c1cf2314b47e9852d66f5712e011e |
File details
Details for the file anyioc-0.15.0-py3-none-any.whl
.
File metadata
- Download URL: anyioc-0.15.0-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.7 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a448c794c34917667954ad49c9c966000cd85511bd4daaf11ef55e435262aa0 |
|
MD5 | ff70476c1b3b84d1a59d5eb0f9d8e6c0 |
|
BLAKE2b-256 | 8af6a67aaeeceda59678e6ed61e9005fa667bc0599841981ce894c401ebf2898 |