python-dependency-injector/examples/applications/ghnav-flask/githubnavigator/application.py

39 lines
948 B
Python
Raw Normal View History

"""Application module."""
from dependency_injector import containers, providers
2020-07-10 03:04:25 +03:00
from github import Github
2020-07-10 03:02:17 +03:00
from . import services, views, webapp
class Application(containers.DeclarativeContainer):
"""Application container."""
config = providers.Configuration()
github_client = providers.Factory(
2020-07-10 03:04:25 +03:00
Github,
2020-07-10 03:02:17 +03:00
login_or_token=config.github.auth_token,
timeout=config.github.request_timeout,
)
search_service = providers.Factory(
services.SearchService,
github_client=github_client,
)
index_view = providers.Callable(
views.index,
2020-07-10 03:02:17 +03:00
search_service=search_service,
default_search_term=config.search.default_term,
default_search_limit=config.search.default_limit,
)
app = providers.Factory(
webapp.create_app,
name=__name__,
routes=[
webapp.Route('/', 'index', index_view, methods=['GET']),
],
)