mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-26 03:23:58 +03:00
Replacing custom providers documentation example with literalinclude
This commit is contained in:
parent
051ed8cb7b
commit
a822f9e6d2
|
@ -30,44 +30,5 @@ Example:
|
|||
:width: 100%
|
||||
:align: center
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
"""Custom `Factory` example."""
|
||||
|
||||
from objects.providers import Provider
|
||||
from objects.providers import Factory
|
||||
|
||||
|
||||
class User(object):
|
||||
|
||||
"""Example class User."""
|
||||
|
||||
|
||||
class UsersFactory(Provider):
|
||||
|
||||
"""Example users factory."""
|
||||
|
||||
__slots__ = ('_factory',)
|
||||
|
||||
def __init__(self):
|
||||
"""Initializer."""
|
||||
self._factory = Factory(User)
|
||||
super(UsersFactory, self).__init__()
|
||||
|
||||
def _provide(self, *args, **kwargs):
|
||||
"""Return provided instance."""
|
||||
return self._factory(*args, **kwargs)
|
||||
|
||||
|
||||
# Users factory:
|
||||
users_factory = UsersFactory()
|
||||
|
||||
# Creating several User objects:
|
||||
user1 = users_factory()
|
||||
user2 = users_factory()
|
||||
|
||||
# Making some asserts:
|
||||
assert isinstance(user1, User)
|
||||
assert isinstance(user2, User)
|
||||
assert user1 is not user2
|
||||
|
||||
.. literalinclude:: ../../examples/providers/custom_factory.py
|
||||
:language: python
|
||||
|
|
Loading…
Reference in New Issue
Block a user