Fixed static di injection
This commit is contained in:
parent
48d0daabf5
commit
6389a940bc
@ -4,7 +4,7 @@
|
|||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "12",
|
"Minor": "12",
|
||||||
"Micro": "1"
|
"Micro": "1.post1"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
@ -13,14 +13,16 @@ class ServiceProviderABC(ABC):
|
|||||||
_provider: Optional['ServiceProviderABC'] = None
|
_provider: Optional['ServiceProviderABC'] = None
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self): pass
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_global_provider(cls, provider: 'ServiceProviderABC'):
|
def set_global_provider(cls, provider: 'ServiceProviderABC'):
|
||||||
cls._provider = provider
|
cls._provider = provider
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def build_by_signature(self, sig: Signature) -> list[T]: pass
|
def build_by_signature(self, sig: Signature) -> list[T]:
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def build_service(self, service_type: type) -> object:
|
def build_service(self, service_type: type) -> object:
|
||||||
@ -108,7 +110,7 @@ class ServiceProviderABC(ABC):
|
|||||||
if cls._provider is None:
|
if cls._provider is None:
|
||||||
raise Exception(f'{cls.__name__} not build!')
|
raise Exception(f'{cls.__name__} not build!')
|
||||||
|
|
||||||
injection = cls._provider.build_by_signature(signature(f))
|
injection = [x for x in cls._provider.build_by_signature(signature(f)) if x is not None]
|
||||||
return f(*injection, *args, **kwargs)
|
return f(*injection, *args, **kwargs)
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
Loading…
Reference in New Issue
Block a user