Update container examples with namedtuples

This commit is contained in:
Roman Mogilatov 2016-06-08 16:52:58 +03:00
parent 14ca5651df
commit 8d1ae1a840
2 changed files with 7 additions and 21 deletions

View File

@ -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):

View File

@ -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):