Add container usage for callable provider example

This commit is contained in:
Roman Mogylatov 2020-09-03 16:57:35 -04:00
parent 1eb9020a4e
commit a497cb2527

View File

@ -2,17 +2,22 @@
import passlib.hash
from dependency_injector import providers
from dependency_injector import containers, providers
password_hasher = providers.Callable(
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)
)
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)