mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-06-15 02:53:12 +03:00
Update and rename callbacks_based_container example
This commit is contained in:
parent
b2d5819da7
commit
ed7f354afe
|
@ -1,8 +1,8 @@
|
||||||
"""Pythonic way for Dependency Injection - Providing Callbacks Catalog."""
|
"""Pythonic way for Dependency Injection - callback-based IoC container."""
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from dependency_injector import catalogs
|
from dependency_injector import containers
|
||||||
from dependency_injector import providers
|
from dependency_injector import providers
|
||||||
from dependency_injector import injections
|
from dependency_injector import injections
|
||||||
|
|
||||||
|
@ -24,14 +24,14 @@ class AuthService(object):
|
||||||
self.users_service = users_service
|
self.users_service = users_service
|
||||||
|
|
||||||
|
|
||||||
class Services(catalogs.DeclarativeCatalog):
|
class Services(containers.DeclarativeContainer):
|
||||||
"""Catalog of service providers."""
|
"""IoC container of service providers."""
|
||||||
|
|
||||||
@providers.Singleton
|
@providers.Singleton
|
||||||
def database():
|
def database():
|
||||||
"""Provide database connection.
|
"""Provide database connection.
|
||||||
|
|
||||||
:rtype: providers.Provider -> sqlite3.Connection
|
:rtype: sqlite3.Connection
|
||||||
"""
|
"""
|
||||||
return sqlite3.connect(':memory:')
|
return sqlite3.connect(':memory:')
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class Services(catalogs.DeclarativeCatalog):
|
||||||
def users(**kwargs):
|
def users(**kwargs):
|
||||||
"""Provide users service.
|
"""Provide users service.
|
||||||
|
|
||||||
:rtype: providers.Provider -> UsersService
|
:rtype: UsersService
|
||||||
"""
|
"""
|
||||||
return UsersService(**kwargs)
|
return UsersService(**kwargs)
|
||||||
|
|
||||||
|
@ -50,12 +50,12 @@ class Services(catalogs.DeclarativeCatalog):
|
||||||
def auth(**kwargs):
|
def auth(**kwargs):
|
||||||
"""Provide users service.
|
"""Provide users service.
|
||||||
|
|
||||||
:rtype: providers.Provider -> AuthService
|
:rtype: AuthService
|
||||||
"""
|
"""
|
||||||
return AuthService(**kwargs)
|
return AuthService(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
# Retrieving catalog providers:
|
# Retrieving services:
|
||||||
users_service = Services.users()
|
users_service = Services.users()
|
||||||
auth_service = Services.auth()
|
auth_service = Services.auth()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user