Remove Key references from the readme

Key's been deprecated.
This commit is contained in:
Jakub Stasiak 2019-06-15 01:05:42 +02:00 committed by GitHub
parent 50f02e6b83
commit a84d4c84e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -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")')