Update movie lister example miniapp

This commit is contained in:
Roman Mogilatov 2017-05-08 18:55:14 +03:00
parent d8d910d342
commit fee8530b1e
5 changed files with 25 additions and 24 deletions

View File

@ -17,6 +17,7 @@ Development version
overriding provider, if any. If target provider is not overridden, ``None``
would be returned.
- Update example of writing custom providers.
- Update movie lister example miniapp.
3.4.3
-----

View File

@ -26,17 +26,17 @@ import dependency_injector.providers as providers
class MyMoviesModule(containers.DeclarativeContainer):
"""IoC container for overriding movies module component providers."""
movie_finder = providers.Factory(movies.finders.CsvMovieFinder,
csv_file_path=settings.MOVIES_CSV_PATH,
delimiter=',',
**movies.MoviesModule.movie_finder.kwargs)
finder = providers.Factory(movies.finders.CsvMovieFinder,
csv_file_path=settings.MOVIES_CSV_PATH,
delimiter=',',
**movies.MoviesModule.finder.kwargs)
class CsvApplication(containers.DeclarativeContainer):
"""IoC container of csv application component providers."""
main = providers.Callable(example.main.main,
movie_lister=movies.MoviesModule.movie_lister)
movie_lister=movies.MoviesModule.lister)
init_db = providers.Callable(example.db.init_csv,
movies_data=fixtures.MOVIES_SAMPLE_DATA,

View File

@ -34,16 +34,16 @@ class ResourcesModule(containers.DeclarativeContainer):
class MyMoviesModule(containers.DeclarativeContainer):
"""IoC container for overriding movies module component providers."""
movie_finder = providers.Factory(movies.finders.SqliteMovieFinder,
database=ResourcesModule.database,
**movies.MoviesModule.movie_finder.kwargs)
finder = providers.Factory(movies.finders.SqliteMovieFinder,
database=ResourcesModule.database,
**movies.MoviesModule.finder.kwargs)
class DbApplication(containers.DeclarativeContainer):
"""IoC container of database application component providers."""
main = providers.Callable(example.main.main,
movie_lister=movies.MoviesModule.movie_lister)
movie_lister=movies.MoviesModule.lister)
init_db = providers.Callable(example.db.init_sqlite,
movies_data=fixtures.MOVIES_SAMPLE_DATA,

View File

@ -34,26 +34,26 @@ class ResourcesModule(containers.DeclarativeContainer):
class DbMoviesModule(movies.MoviesModule):
"""IoC container for overriding movies module component providers."""
movie_finder = providers.Factory(movies.finders.SqliteMovieFinder,
database=ResourcesModule.database,
**movies.MoviesModule.movie_finder.kwargs)
finder = providers.Factory(movies.finders.SqliteMovieFinder,
database=ResourcesModule.database,
**movies.MoviesModule.finder.kwargs)
@containers.copy(movies.MoviesModule)
class CsvMoviesModule(movies.MoviesModule):
"""IoC container for overriding movies module component providers."""
movie_finder = providers.Factory(movies.finders.CsvMovieFinder,
csv_file_path=settings.MOVIES_CSV_PATH,
delimiter=',',
**movies.MoviesModule.movie_finder.kwargs)
finder = providers.Factory(movies.finders.CsvMovieFinder,
csv_file_path=settings.MOVIES_CSV_PATH,
delimiter=',',
**movies.MoviesModule.finder.kwargs)
class DbApplication(containers.DeclarativeContainer):
"""IoC container of database application component providers."""
main = providers.Callable(example.main.main,
movie_lister=DbMoviesModule.movie_lister)
movie_lister=DbMoviesModule.lister)
init_db = providers.Callable(example.db.init_sqlite,
movies_data=fixtures.MOVIES_SAMPLE_DATA,
@ -64,7 +64,7 @@ class CsvApplication(containers.DeclarativeContainer):
"""IoC container of csv application component providers."""
main = providers.Callable(example.main.main,
movie_lister=CsvMoviesModule.movie_lister)
movie_lister=CsvMoviesModule.lister)
init_db = providers.Callable(example.db.init_csv,
movies_data=fixtures.MOVIES_SAMPLE_DATA,

View File

@ -5,7 +5,7 @@ movies module component providers - ``MoviesModule``. It is recommended to use
movies library functionality by fetching required instances from
``MoviesModule`` providers.
``MoviesModule.movie_finder`` is a factory that provides abstract component
``MoviesModule.finder`` is a factory that provides abstract component
``finders.MovieFinder``. This provider should be overridden by provider of
concrete finder implementation in terms of library configuration.
@ -23,10 +23,10 @@ import dependency_injector.providers as providers
class MoviesModule(containers.DeclarativeContainer):
"""IoC container of movies module component providers."""
movie_model = providers.DelegatedFactory(movies.models.Movie)
models_factory = providers.Factory(movies.models.Movie)
movie_finder = providers.AbstractFactory(movies.finders.MovieFinder,
movie_model=movie_model)
finder = providers.AbstractFactory(movies.finders.MovieFinder,
movie_model=models_factory.delegate())
movie_lister = providers.Factory(movies.listers.MovieLister,
movie_finder=movie_finder)
lister = providers.Factory(movies.listers.MovieLister,
movie_finder=finder)