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.""" """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):

View File

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