From a84d4c84e31956c958af41adf3885524d2be2195 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Sat, 15 Jun 2019 01:05:42 +0200 Subject: [PATCH] Remove Key references from the readme Key's been deprecated. --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b9cf62c..989416d 100644 --- a/README.md +++ b/README.md @@ -105,20 +105,21 @@ And make up an imaginary `RequestHandler` class that uses the SQLite connection: ``` -Next, for the sake of the example, we'll create a "configuration" annotated type: +Next, for the sake of the example, we'll create a configuration type: ```python ->>> Configuration = Key('configuration') - +>>> class Configuration: +... def __init__(self, connection_string): +... self.connection_string = connection_string ``` -Key is used to uniquely identify the configuration dictionary. Next, we bind the configuration to the injector, using a module: +Next, we bind the configuration to the injector, using a module: ```python >>> def configure_for_testing(binder): -... configuration = {'db_connection_string': ':memory:'} +... configuration = Configuration(':memory:') ... binder.bind(Configuration, to=configuration, scope=singleton) ``` @@ -131,7 +132,7 @@ Next we create a module that initialises the DB. It depends on the configuration ... @singleton ... @provider ... def provide_sqlite_connection(self, configuration: Configuration) -> sqlite3.Connection: -... conn = sqlite3.connect(configuration['db_connection_string']) +... conn = sqlite3.connect(configuration.connection_string) ... cursor = conn.cursor() ... cursor.execute('CREATE TABLE IF NOT EXISTS data (key PRIMARY KEY, value)') ... cursor.execute('INSERT OR REPLACE INTO data VALUES ("hello", "world")')