mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Update imports for movie lister example
This commit is contained in:
parent
ab7c8ac4d1
commit
bf9b1205b6
|
@ -9,27 +9,27 @@ This mini application uses ``movies`` library, that is configured to work with
|
|||
csv file movies database.
|
||||
"""
|
||||
|
||||
from dependency_injector import containers
|
||||
from dependency_injector import providers
|
||||
from dependency_injector import injections
|
||||
import dependency_injector.containers as containers
|
||||
import dependency_injector.providers as providers
|
||||
import dependency_injector.injections as di
|
||||
|
||||
from movies import MoviesModule
|
||||
from movies import finders
|
||||
import movies
|
||||
import movies.finders
|
||||
|
||||
from settings import MOVIES_CSV_PATH
|
||||
import settings
|
||||
|
||||
|
||||
@containers.override(MoviesModule)
|
||||
@containers.override(movies.MoviesModule)
|
||||
class MyMoviesModule(containers.DeclarativeContainer):
|
||||
"""IoC container for overriding movies module component providers."""
|
||||
|
||||
movie_finder = providers.Factory(finders.CsvMovieFinder,
|
||||
csv_file=MOVIES_CSV_PATH,
|
||||
movie_finder = providers.Factory(movies.finders.CsvMovieFinder,
|
||||
csv_file=settings.MOVIES_CSV_PATH,
|
||||
delimeter=',',
|
||||
**MoviesModule.movie_finder.kwargs)
|
||||
**movies.MoviesModule.movie_finder.kwargs)
|
||||
|
||||
|
||||
@injections.inject(MoviesModule.movie_lister)
|
||||
@di.inject(movies.MoviesModule.movie_lister)
|
||||
def main(movie_lister):
|
||||
"""Main function.
|
||||
|
||||
|
|
|
@ -11,32 +11,32 @@ sqlite movies database.
|
|||
|
||||
import sqlite3
|
||||
|
||||
from dependency_injector import containers
|
||||
from dependency_injector import providers
|
||||
from dependency_injector import injections
|
||||
import dependency_injector.containers as containers
|
||||
import dependency_injector.providers as providers
|
||||
import dependency_injector.injections as di
|
||||
|
||||
from movies import MoviesModule
|
||||
from movies import finders
|
||||
import movies
|
||||
import movies.finders
|
||||
|
||||
from settings import MOVIES_DB_PATH
|
||||
import settings
|
||||
|
||||
|
||||
class ApplicationModule(containers.DeclarativeContainer):
|
||||
"""IoC container of application component providers."""
|
||||
|
||||
database = providers.Singleton(sqlite3.connect, MOVIES_DB_PATH)
|
||||
database = providers.Singleton(sqlite3.connect, settings.MOVIES_DB_PATH)
|
||||
|
||||
|
||||
@containers.override(MoviesModule)
|
||||
@containers.override(movies.MoviesModule)
|
||||
class MyMoviesModule(containers.DeclarativeContainer):
|
||||
"""IoC container for overriding movies module component providers."""
|
||||
|
||||
movie_finder = providers.Factory(finders.SqliteMovieFinder,
|
||||
movie_finder = providers.Factory(movies.finders.SqliteMovieFinder,
|
||||
database=ApplicationModule.database,
|
||||
**MoviesModule.movie_finder.kwargs)
|
||||
**movies.MoviesModule.movie_finder.kwargs)
|
||||
|
||||
|
||||
@injections.inject(MoviesModule.movie_lister)
|
||||
@di.inject(movies.MoviesModule.movie_lister)
|
||||
def main(movie_lister):
|
||||
"""Main function.
|
||||
|
||||
|
|
|
@ -11,44 +11,43 @@ sqlite movies database and csv file movies database.
|
|||
|
||||
import sqlite3
|
||||
|
||||
from dependency_injector import containers
|
||||
from dependency_injector import providers
|
||||
from dependency_injector import injections
|
||||
import dependency_injector.containers as containers
|
||||
import dependency_injector.providers as providers
|
||||
import dependency_injector.injections as di
|
||||
|
||||
from movies import MoviesModule
|
||||
from movies import finders
|
||||
import movies
|
||||
import movies.finders
|
||||
|
||||
from settings import MOVIES_CSV_PATH
|
||||
from settings import MOVIES_DB_PATH
|
||||
import settings
|
||||
|
||||
|
||||
class ApplicationModule(containers.DeclarativeContainer):
|
||||
"""IoC container of application component providers."""
|
||||
|
||||
database = providers.Singleton(sqlite3.connect, MOVIES_DB_PATH)
|
||||
database = providers.Singleton(sqlite3.connect, settings.MOVIES_DB_PATH)
|
||||
|
||||
|
||||
@containers.copy(MoviesModule)
|
||||
class DbMoviesModule(MoviesModule):
|
||||
@containers.copy(movies.MoviesModule)
|
||||
class DbMoviesModule(movies.MoviesModule):
|
||||
"""IoC container for overriding movies module component providers."""
|
||||
|
||||
movie_finder = providers.Factory(finders.SqliteMovieFinder,
|
||||
movie_finder = providers.Factory(movies.finders.SqliteMovieFinder,
|
||||
database=ApplicationModule.database,
|
||||
**MoviesModule.movie_finder.kwargs)
|
||||
**movies.MoviesModule.movie_finder.kwargs)
|
||||
|
||||
|
||||
@containers.copy(MoviesModule)
|
||||
class CsvMoviesModule(MoviesModule):
|
||||
@containers.copy(movies.MoviesModule)
|
||||
class CsvMoviesModule(movies.MoviesModule):
|
||||
"""IoC container for overriding movies module component providers."""
|
||||
|
||||
movie_finder = providers.Factory(finders.CsvMovieFinder,
|
||||
csv_file=MOVIES_CSV_PATH,
|
||||
movie_finder = providers.Factory(movies.finders.CsvMovieFinder,
|
||||
csv_file=settings.MOVIES_CSV_PATH,
|
||||
delimeter=',',
|
||||
**MoviesModule.movie_finder.kwargs)
|
||||
**movies.MoviesModule.movie_finder.kwargs)
|
||||
|
||||
|
||||
@injections.inject(db_movie_lister=DbMoviesModule.movie_lister)
|
||||
@injections.inject(csv_movie_lister=CsvMoviesModule.movie_lister)
|
||||
@di.inject(db_movie_lister=DbMoviesModule.movie_lister)
|
||||
@di.inject(csv_movie_lister=CsvMoviesModule.movie_lister)
|
||||
def main(db_movie_lister, csv_movie_lister):
|
||||
"""Main function.
|
||||
|
||||
|
|
|
@ -12,21 +12,21 @@ concrete finder implementation in terms of library configuration.
|
|||
Each of ``MoviesModule`` providers could be overridden.
|
||||
"""
|
||||
|
||||
from dependency_injector import containers
|
||||
from dependency_injector import providers
|
||||
import dependency_injector.containers as containers
|
||||
import dependency_injector.providers as providers
|
||||
|
||||
from . import finders
|
||||
from . import listers
|
||||
from . import models
|
||||
import movies.finders
|
||||
import movies.listers
|
||||
import movies.models
|
||||
|
||||
|
||||
class MoviesModule(containers.DeclarativeContainer):
|
||||
"""IoC container of movies module component providers."""
|
||||
|
||||
movie_model = providers.DelegatedFactory(models.Movie)
|
||||
movie_model = providers.DelegatedFactory(movies.models.Movie)
|
||||
|
||||
movie_finder = providers.Factory(finders.MovieFinder,
|
||||
movie_finder = providers.Factory(movies.finders.MovieFinder,
|
||||
movie_model=movie_model)
|
||||
|
||||
movie_lister = providers.Factory(listers.MovieLister,
|
||||
movie_lister = providers.Factory(movies.listers.MovieLister,
|
||||
movie_finder=movie_finder)
|
||||
|
|
Loading…
Reference in New Issue
Block a user