mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-07 07:00:49 +03:00
Updating docs structure
This commit is contained in:
parent
f278f21101
commit
ae95ecf711
|
@ -37,82 +37,6 @@ that will be called to provide injectable value.
|
|||
example_callback()
|
||||
example_callback()
|
||||
|
||||
Overriding providers
|
||||
--------------------
|
||||
|
||||
Any provider can be overridden by another provider.
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
"""Provider overriding example."""
|
||||
|
||||
import sqlite3
|
||||
|
||||
from objects.providers import Singleton
|
||||
from objects.providers import NewInstance
|
||||
|
||||
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')
|
||||
|
||||
|
||||
class ObjectAMock(ObjectA):
|
||||
|
||||
"""Mock of ObjectA.
|
||||
|
||||
Has no dependency on database.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""Initializer."""
|
||||
|
||||
def get_one(self):
|
||||
"""Select one from database and return it.
|
||||
|
||||
Mock makes no database queries and always returns two instead of one.
|
||||
"""
|
||||
return 2
|
||||
|
||||
|
||||
# Database and `ObjectA` providers.
|
||||
database = Singleton(sqlite3.Connection,
|
||||
KwArg('database', ':memory:'),
|
||||
KwArg('timeout', 30),
|
||||
KwArg('detect_types', True),
|
||||
KwArg('isolation_level', 'EXCLUSIVE'),
|
||||
Attribute('row_factory', sqlite3.Row))
|
||||
|
||||
object_a = NewInstance(ObjectA,
|
||||
KwArg('database', database))
|
||||
|
||||
|
||||
# Overriding `ObjectA` provider with `ObjectAMock` provider.
|
||||
object_a.override(NewInstance(ObjectAMock))
|
||||
|
||||
# Creating several `ObjectA` instances.
|
||||
object_a_1 = object_a()
|
||||
object_a_2 = object_a()
|
||||
|
||||
# Making some asserts.
|
||||
assert object_a_1 is not object_a_2
|
||||
assert object_a_1.get_one() == object_a_2.get_one() == 2
|
||||
|
||||
Overriding catalogs
|
||||
-------------------
|
||||
|
||||
|
|
|
@ -1,2 +1,11 @@
|
|||
Catalogs
|
||||
========
|
||||
|
||||
Writing catalogs
|
||||
----------------
|
||||
|
||||
Creating catalogs from modules
|
||||
------------------------------
|
||||
|
||||
@override decorator
|
||||
-------------------
|
||||
|
|
2
docs/changelog.rst
Normal file
2
docs/changelog.rst
Normal file
|
@ -0,0 +1,2 @@
|
|||
Changelog
|
||||
=========
|
|
@ -1,7 +1,5 @@
|
|||
Decorators
|
||||
==========
|
||||
|
||||
Current section of *Objects* documentation describes several useful decorators.
|
||||
Inline injections
|
||||
=================
|
||||
|
||||
@inject decorator
|
||||
-----------------
|
||||
|
@ -46,6 +44,3 @@ decorator:
|
|||
example_callback()
|
||||
example_callback()
|
||||
|
||||
|
||||
@override decorator
|
||||
-------------------
|
||||
|
|
|
@ -39,8 +39,8 @@ Contents
|
|||
introduction
|
||||
installation
|
||||
providers/index
|
||||
injections
|
||||
catalogs
|
||||
decorators
|
||||
examples
|
||||
feedback
|
||||
changelog
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
Installation
|
||||
============
|
||||
|
||||
Latest stable version
|
||||
---------------------
|
||||
|
||||
Latest stable version of *Objects* framework can be installed from PyPi_:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install objects
|
||||
|
||||
|
||||
Sources can be cloned from GitHub_:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
git clone https://github.com/rmk135/objects.git
|
||||
|
||||
Previous releases
|
||||
-----------------
|
||||
|
||||
All *Objects* releases can be found on GitHub: https://github.com/rmk135/objects/releases
|
||||
|
||||
.. _PyPi: https://pypi.python.org/pypi/Objects
|
||||
|
|
Loading…
Reference in New Issue
Block a user