mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-29 13:04:02 +03:00
Update README with new containers
This commit is contained in:
parent
7206b4dbb8
commit
05c2c864a7
30
README.rst
30
README.rst
|
@ -52,7 +52,7 @@ Installation
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
||||||
Brief example below demonstrates usage of *Dependency Injector* catalogs and
|
Brief example below demonstrates usage of *Dependency Injector* containers and
|
||||||
providers for definition of several IoC containers for some microservice
|
providers for definition of several IoC containers for some microservice
|
||||||
system that consists from several business and platform services:
|
system that consists from several business and platform services:
|
||||||
|
|
||||||
|
@ -64,12 +64,12 @@ system that consists from several business and platform services:
|
||||||
import boto.s3.connection
|
import boto.s3.connection
|
||||||
import example.services
|
import example.services
|
||||||
|
|
||||||
from dependency_injector import catalogs
|
from dependency_injector import containers
|
||||||
from dependency_injector import providers
|
from dependency_injector import providers
|
||||||
|
|
||||||
|
|
||||||
class Platform(catalogs.DeclarativeCatalog):
|
class Platform(containers.DeclarativeContainer):
|
||||||
"""Catalog of platform service providers."""
|
"""Container of platform service providers."""
|
||||||
|
|
||||||
database = providers.Singleton(sqlite3.connect, ':memory:')
|
database = providers.Singleton(sqlite3.connect, ':memory:')
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ system that consists from several business and platform services:
|
||||||
aws_secret_access_key='SECRET')
|
aws_secret_access_key='SECRET')
|
||||||
|
|
||||||
|
|
||||||
class Services(catalogs.DeclarativeCatalog):
|
class Services(containers.DeclarativeContainer):
|
||||||
"""Catalog of business service providers."""
|
"""Container of business service providers."""
|
||||||
|
|
||||||
users = providers.Factory(example.services.Users,
|
users = providers.Factory(example.services.Users,
|
||||||
db=Platform.database)
|
db=Platform.database)
|
||||||
|
@ -101,7 +101,7 @@ defined above:
|
||||||
|
|
||||||
from dependency_injector.injections import inject
|
from dependency_injector.injections import inject
|
||||||
|
|
||||||
from catalogs import Services
|
from containers import Services
|
||||||
|
|
||||||
|
|
||||||
@inject(users_service=Services.users)
|
@inject(users_service=Services.users)
|
||||||
|
@ -127,8 +127,8 @@ IoC containers from previous example could look like these:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
class Platform(catalogs.DeclarativeCatalog):
|
class Platform(containers.DeclarativeContainer):
|
||||||
"""Catalog of platform service providers."""
|
"""Container of platform service providers."""
|
||||||
|
|
||||||
database = providers.Singleton(sqlite3.connect) \
|
database = providers.Singleton(sqlite3.connect) \
|
||||||
.add_args(':memory:')
|
.add_args(':memory:')
|
||||||
|
@ -138,8 +138,8 @@ IoC containers from previous example could look like these:
|
||||||
aws_secret_access_key='SECRET')
|
aws_secret_access_key='SECRET')
|
||||||
|
|
||||||
|
|
||||||
class Services(catalogs.DeclarativeCatalog):
|
class Services(containers.DeclarativeContainer):
|
||||||
"""Catalog of business service providers."""
|
"""Container of business service providers."""
|
||||||
|
|
||||||
users = providers.Factory(example.services.Users) \
|
users = providers.Factory(example.services.Users) \
|
||||||
.add_kwargs(db=Platform.database)
|
.add_kwargs(db=Platform.database)
|
||||||
|
@ -156,8 +156,8 @@ or like this these:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
class Platform(catalogs.DeclarativeCatalog):
|
class Platform(containers.DeclarativeContainer):
|
||||||
"""Catalog of platform service providers."""
|
"""Container of platform service providers."""
|
||||||
|
|
||||||
database = providers.Singleton(sqlite3.connect)
|
database = providers.Singleton(sqlite3.connect)
|
||||||
database.add_args(':memory:')
|
database.add_args(':memory:')
|
||||||
|
@ -167,8 +167,8 @@ or like this these:
|
||||||
aws_secret_access_key='SECRET')
|
aws_secret_access_key='SECRET')
|
||||||
|
|
||||||
|
|
||||||
class Services(catalogs.DeclarativeCatalog):
|
class Services(containers.DeclarativeContainer):
|
||||||
"""Catalog of business service providers."""
|
"""Container of business service providers."""
|
||||||
|
|
||||||
users = providers.Factory(example.services.Users)
|
users = providers.Factory(example.services.Users)
|
||||||
users.add_kwargs(db=Platform.database)
|
users.add_kwargs(db=Platform.database)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user