mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-26 11:33:58 +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."""
|
"""Declarative IoC container's provider injections example."""
|
||||||
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import collections
|
||||||
|
|
||||||
import dependency_injector.containers as containers
|
import dependency_injector.containers as containers
|
||||||
import dependency_injector.providers as providers
|
import dependency_injector.providers as providers
|
||||||
|
|
||||||
|
|
||||||
class UsersService(object):
|
UsersService = collections.namedtuple('UsersService', ['db'])
|
||||||
"""Users service, that has dependency on database."""
|
AuthService = collections.namedtuple('AuthService', ['db', 'users_service'])
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class Services(containers.DeclarativeContainer):
|
class Services(containers.DeclarativeContainer):
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
"""Creation of dynamic container based on some configuration example."""
|
"""Creation of dynamic container based on some configuration example."""
|
||||||
|
|
||||||
|
import collections
|
||||||
|
|
||||||
import dependency_injector.containers as containers
|
import dependency_injector.containers as containers
|
||||||
|
|
||||||
|
|
||||||
# Defining several example services:
|
# Defining several example services:
|
||||||
class UsersService(object):
|
UsersService = collections.namedtuple('UsersService', [])
|
||||||
"""Example users service."""
|
AuthService = collections.namedtuple('AuthService', [])
|
||||||
|
|
||||||
|
|
||||||
class AuthService(object):
|
|
||||||
"""Example auth service."""
|
|
||||||
|
|
||||||
|
|
||||||
def import_cls(cls_name):
|
def import_cls(cls_name):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user