mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-06 14:40:48 +03:00
Update README
This commit is contained in:
parent
711fd64037
commit
fabe6d8a5d
69
README.rst
69
README.rst
|
@ -57,12 +57,10 @@ Example:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
import sqlite3
|
|
||||||
|
|
||||||
import boto3
|
|
||||||
from dependency_injector import containers, providers
|
from dependency_injector import containers, providers
|
||||||
|
from github import Github
|
||||||
from .example import services
|
|
||||||
|
from . import services, views, webapp
|
||||||
|
|
||||||
|
|
||||||
class Application(containers.DeclarativeContainer):
|
class Application(containers.DeclarativeContainer):
|
||||||
|
@ -70,58 +68,33 @@ Example:
|
||||||
|
|
||||||
config = providers.Configuration()
|
config = providers.Configuration()
|
||||||
|
|
||||||
# Gateways
|
github_client = providers.Factory(
|
||||||
|
Github,
|
||||||
database_client = providers.Singleton(sqlite3.connect, config.database.dsn)
|
login_or_token=config.github.auth_token,
|
||||||
|
timeout=config.github.request_timeout,
|
||||||
s3_client = providers.Singleton(
|
|
||||||
boto3.client, 's3',
|
|
||||||
aws_access_key_id=config.aws.access_key_id,
|
|
||||||
aws_secret_access_key=config.aws.secret_access_key,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Services
|
search_service = providers.Factory(
|
||||||
|
services.SearchService,
|
||||||
users_service = providers.Factory(
|
github_client=github_client,
|
||||||
services.UsersService,
|
|
||||||
db=database_client,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
auth_service = providers.Factory(
|
index_view = providers.Callable(
|
||||||
services.AuthService,
|
views.index,
|
||||||
token_ttl=config.auth.token_ttl,
|
search_service=search_service,
|
||||||
db=database_client,
|
default_search_term=config.search.default_term,
|
||||||
|
default_search_limit=config.search.default_limit,
|
||||||
)
|
)
|
||||||
|
|
||||||
photos_service = providers.Factory(
|
app = providers.Factory(
|
||||||
services.PhotosService,
|
webapp.create_app,
|
||||||
db=database_client,
|
name=__name__,
|
||||||
s3=s3_client,
|
routes=[
|
||||||
|
webapp.Route('/', 'index', index_view, methods=['GET']),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
Run the application:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
from .application import Application
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""Run application."""
|
|
||||||
application = Application()
|
|
||||||
application.config.from_yaml('config.yml')
|
|
||||||
|
|
||||||
users_service = application.users_service()
|
|
||||||
auth_service = application.auth_service()
|
|
||||||
photos_service = application.photos_service()
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|
||||||
You can find more ``Dependency Injector`` examples in the ``/examples`` directory
|
You can find more ``Dependency Injector`` examples in the ``/examples`` directory
|
||||||
on the GitHub:
|
on the GitHub:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user