mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 01:26:51 +03:00
adding some comments to example, switch prints to asserts for making example easier readable
This commit is contained in:
parent
4c20f9c968
commit
7824ba10fa
12
README.md
12
README.md
|
@ -15,6 +15,7 @@ import objects
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
# Some example classes.
|
||||||
class A(object):
|
class A(object):
|
||||||
def __init__(self, db):
|
def __init__(self, db):
|
||||||
self.db = db
|
self.db = db
|
||||||
|
@ -26,6 +27,7 @@ class B(object):
|
||||||
self.db = db
|
self.db = db
|
||||||
|
|
||||||
|
|
||||||
|
# Catalog of objects providers.
|
||||||
class Catalog(objects.Catalog):
|
class Catalog(objects.Catalog):
|
||||||
"""
|
"""
|
||||||
Objects catalog.
|
Objects catalog.
|
||||||
|
@ -45,6 +47,7 @@ class Catalog(objects.Catalog):
|
||||||
""" :type: (objects.Provider) -> B """
|
""" :type: (objects.Provider) -> B """
|
||||||
|
|
||||||
|
|
||||||
|
# Catalog injection into consumer class.
|
||||||
class Consumer(object):
|
class Consumer(object):
|
||||||
catalog = Catalog(Catalog.object_a,
|
catalog = Catalog(Catalog.object_a,
|
||||||
Catalog.object_b)
|
Catalog.object_b)
|
||||||
|
@ -55,14 +58,13 @@ class Consumer(object):
|
||||||
|
|
||||||
a1, b1 = Consumer().return_a_b()
|
a1, b1 = Consumer().return_a_b()
|
||||||
|
|
||||||
|
|
||||||
|
# Catalog static provides.
|
||||||
a2 = Catalog.object_a()
|
a2 = Catalog.object_a()
|
||||||
b2 = Catalog.object_b()
|
b2 = Catalog.object_b()
|
||||||
|
|
||||||
print a1, a1.db
|
# Some asserts.
|
||||||
print a2, a2.db
|
|
||||||
print b1, b1.db
|
|
||||||
print b2, b2.db
|
|
||||||
|
|
||||||
assert a1 is not a2
|
assert a1 is not a2
|
||||||
assert b1 is not b2
|
assert b1 is not b2
|
||||||
|
assert a1.db is a2.db is b1.db is b2.db
|
||||||
```
|
```
|
||||||
|
|
|
@ -6,6 +6,7 @@ import objects
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
# Some example classes.
|
||||||
class A(object):
|
class A(object):
|
||||||
def __init__(self, db):
|
def __init__(self, db):
|
||||||
self.db = db
|
self.db = db
|
||||||
|
@ -17,6 +18,7 @@ class B(object):
|
||||||
self.db = db
|
self.db = db
|
||||||
|
|
||||||
|
|
||||||
|
# Catalog of objects providers.
|
||||||
class Catalog(objects.Catalog):
|
class Catalog(objects.Catalog):
|
||||||
"""
|
"""
|
||||||
Objects catalog.
|
Objects catalog.
|
||||||
|
@ -36,6 +38,7 @@ class Catalog(objects.Catalog):
|
||||||
""" :type: (objects.Provider) -> B """
|
""" :type: (objects.Provider) -> B """
|
||||||
|
|
||||||
|
|
||||||
|
# Catalog injection into consumer class.
|
||||||
class Consumer(object):
|
class Consumer(object):
|
||||||
catalog = Catalog(Catalog.object_a,
|
catalog = Catalog(Catalog.object_a,
|
||||||
Catalog.object_b)
|
Catalog.object_b)
|
||||||
|
@ -46,13 +49,12 @@ class Consumer(object):
|
||||||
|
|
||||||
a1, b1 = Consumer().return_a_b()
|
a1, b1 = Consumer().return_a_b()
|
||||||
|
|
||||||
|
|
||||||
|
# Catalog static provides.
|
||||||
a2 = Catalog.object_a()
|
a2 = Catalog.object_a()
|
||||||
b2 = Catalog.object_b()
|
b2 = Catalog.object_b()
|
||||||
|
|
||||||
print a1, a1.db
|
# Some asserts.
|
||||||
print a2, a2.db
|
|
||||||
print b1, b1.db
|
|
||||||
print b2, b2.db
|
|
||||||
|
|
||||||
assert a1 is not a2
|
assert a1 is not a2
|
||||||
assert b1 is not b2
|
assert b1 is not b2
|
||||||
|
assert a1.db is a2.db is b1.db is b2.db
|
||||||
|
|
Loading…
Reference in New Issue
Block a user