From a497cb2527773ec4c1bc0ebd77e3de56cb9a5d27 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Thu, 3 Sep 2020 16:57:35 -0400 Subject: [PATCH] Add container usage for callable provider example --- examples/providers/callable.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/examples/providers/callable.py b/examples/providers/callable.py index 40e0d363..82d18e38 100644 --- a/examples/providers/callable.py +++ b/examples/providers/callable.py @@ -2,17 +2,22 @@ import passlib.hash -from dependency_injector import providers +from dependency_injector import containers, providers -password_hasher = providers.Callable( - passlib.hash.sha256_crypt.hash, - salt_size=16, - rounds=10000, -) -password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify) +class Container(containers.DeclarativeContainer): + + password_hasher = providers.Callable( + passlib.hash.sha256_crypt.hash, + salt_size=16, + rounds=10000, + ) + + password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify) if __name__ == '__main__': - hashed_password = password_hasher('super secret') - assert password_verifier('super secret', hashed_password) + container = Container() + + hashed_password = container.password_hasher('super secret') + assert container.password_verifier('super secret', hashed_password)