From fee8530b1e9a58c067e741682a9c2310cfdd98cb Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Mon, 8 May 2017 18:55:14 +0300 Subject: [PATCH] Update movie lister example miniapp --- docs/main/changelog.rst | 1 + examples/miniapps/movie_lister/app_csv.py | 10 +++++----- examples/miniapps/movie_lister/app_db.py | 8 ++++---- examples/miniapps/movie_lister/app_db_csv.py | 18 +++++++++--------- .../miniapps/movie_lister/movies/__init__.py | 12 ++++++------ 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index d181ed2c..57ef7845 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -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 ----- diff --git a/examples/miniapps/movie_lister/app_csv.py b/examples/miniapps/movie_lister/app_csv.py index 497d4e49..052492bc 100644 --- a/examples/miniapps/movie_lister/app_csv.py +++ b/examples/miniapps/movie_lister/app_csv.py @@ -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, diff --git a/examples/miniapps/movie_lister/app_db.py b/examples/miniapps/movie_lister/app_db.py index 7eb02e6e..dee6bdae 100644 --- a/examples/miniapps/movie_lister/app_db.py +++ b/examples/miniapps/movie_lister/app_db.py @@ -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, diff --git a/examples/miniapps/movie_lister/app_db_csv.py b/examples/miniapps/movie_lister/app_db_csv.py index 2f2864d8..9822ff1d 100644 --- a/examples/miniapps/movie_lister/app_db_csv.py +++ b/examples/miniapps/movie_lister/app_db_csv.py @@ -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, diff --git a/examples/miniapps/movie_lister/movies/__init__.py b/examples/miniapps/movie_lister/movies/__init__.py index 71fa6672..11cdd27d 100644 --- a/examples/miniapps/movie_lister/movies/__init__.py +++ b/examples/miniapps/movie_lister/movies/__init__.py @@ -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)