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 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, passlib.hash.sha256_crypt.hash,
salt_size=16, salt_size=16,
rounds=10000, rounds=10000,
) )
password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify)
password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify)
if __name__ == '__main__': if __name__ == '__main__':
hashed_password = password_hasher('super secret') container = Container()
assert password_verifier('super secret', hashed_password)
hashed_password = container.password_hasher('super secret')
assert container.password_verifier('super secret', hashed_password)