mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
Update container examples with namedtuples
This commit is contained in:
parent
14ca5651df
commit
8d1ae1a840
|
@ -1,26 +1,14 @@
|
|||
"""Declarative IoC container's provider injections example."""
|
||||
|
||||
import sqlite3
|
||||
import collections
|
||||
|
||||
import dependency_injector.containers as containers
|
||||
import dependency_injector.providers as providers
|
||||
|
||||
|
||||
class UsersService(object):
|
||||
"""Users service, that has dependency on database."""
|
||||
|
||||
def __init__(self, db):
|
||||
"""Initializer."""
|
||||
self.db = db
|
||||
|
||||
|
||||
class AuthService(object):
|
||||
"""Auth service, that has dependencies on users service and database."""
|
||||
|
||||
def __init__(self, db, users_service):
|
||||
"""Initializer."""
|
||||
self.db = db
|
||||
self.users_service = users_service
|
||||
UsersService = collections.namedtuple('UsersService', ['db'])
|
||||
AuthService = collections.namedtuple('AuthService', ['db', 'users_service'])
|
||||
|
||||
|
||||
class Services(containers.DeclarativeContainer):
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
"""Creation of dynamic container based on some configuration example."""
|
||||
|
||||
import collections
|
||||
|
||||
import dependency_injector.containers as containers
|
||||
|
||||
|
||||
# Defining several example services:
|
||||
class UsersService(object):
|
||||
"""Example users service."""
|
||||
|
||||
|
||||
class AuthService(object):
|
||||
"""Example auth service."""
|
||||
UsersService = collections.namedtuple('UsersService', [])
|
||||
AuthService = collections.namedtuple('AuthService', [])
|
||||
|
||||
|
||||
def import_cls(cls_name):
|
||||
|
|
Loading…
Reference in New Issue
Block a user