From 8b479a189810e07f5776eb1a310bf55812f168bb Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Thu, 18 Jun 2015 16:37:19 +0300 Subject: [PATCH] Removing old external dependency provider example --- .../readme2/external_dependency_providers.py | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 examples/readme2/external_dependency_providers.py diff --git a/examples/readme2/external_dependency_providers.py b/examples/readme2/external_dependency_providers.py deleted file mode 100644 index f920b814..00000000 --- a/examples/readme2/external_dependency_providers.py +++ /dev/null @@ -1,48 +0,0 @@ -"""External dependency providers example.""" - -import sqlite3 - -from objects.providers import Singleton -from objects.providers import Factory -from objects.providers import ExternalDependency - -from objects.injections import KwArg -from objects.injections import Attribute - - -class ObjectA(object): - - """ObjectA has dependency on database.""" - - def __init__(self, database): - """Initializer. - - Database dependency need to be injected via init arg.""" - self.database = database - - def get_one(self): - """Select one from database and return it.""" - return self.database.execute('SELECT 1').fetchone()[0] - - -# Database and `ObjectA` providers. -database = ExternalDependency(instance_of=sqlite3.Connection) - -object_a_factory = Factory(ObjectA, - KwArg('database', database)) - -# Satisfaction of external dependency. -database.override(Singleton(sqlite3.Connection, - KwArg('database', ':memory:'), - KwArg('timeout', 30), - KwArg('detect_types', True), - KwArg('isolation_level', 'EXCLUSIVE'), - Attribute('row_factory', sqlite3.Row))) - -# Creating several `ObjectA` instances. -object_a_1 = object_a_factory() -object_a_2 = object_a_factory() - -# Making some asserts. -assert object_a_1 is not object_a_2 -assert object_a_1.database is object_a_2.database is database()