mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-19 21:10:57 +03:00
Adding possibility to get all providers by type from catalog
This commit is contained in:
parent
ae2d1036d7
commit
7f88e4ffdd
|
@ -33,14 +33,14 @@ class AbstractCatalog(object):
|
||||||
return attribute
|
return attribute
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __all_providers__(cls):
|
def __all_providers__(cls, provider_type=Provider):
|
||||||
"""
|
"""
|
||||||
Returns set of all class providers.
|
Returns set of all class providers.
|
||||||
"""
|
"""
|
||||||
providers = set()
|
providers = set()
|
||||||
for attr_name in set(dir(cls)) - set(dir(AbstractCatalog)):
|
for attr_name in set(dir(cls)) - set(dir(AbstractCatalog)):
|
||||||
provider = getattr(cls, attr_name)
|
provider = getattr(cls, attr_name)
|
||||||
if not isinstance(provider, Provider):
|
if not isinstance(provider, provider_type):
|
||||||
continue
|
continue
|
||||||
providers.add((attr_name, provider))
|
providers.add((attr_name, provider))
|
||||||
return providers
|
return providers
|
||||||
|
|
Loading…
Reference in New Issue
Block a user