#166 #167
@ -294,7 +294,7 @@ class Configuration(ConfigurationABC):
|
|||||||
|
|
||||||
self.add_configuration(sub, configuration)
|
self.add_configuration(sub, configuration)
|
||||||
|
|
||||||
def add_configuration(self, key_type: T, value: any):
|
def add_configuration(self, key_type: Type[T], value: any):
|
||||||
self._config[key_type] = value
|
self._config[key_type] = value
|
||||||
|
|
||||||
def create_console_argument(
|
def create_console_argument(
|
||||||
|
@ -77,7 +77,7 @@ class ConfigurationABC(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_configuration(self, key_type: T, value: any):
|
def add_configuration(self, key_type: Type[T], value: any):
|
||||||
r"""Add configuration object
|
r"""Add configuration object
|
||||||
|
|
||||||
Parameter:
|
Parameter:
|
||||||
|
@ -61,15 +61,15 @@ class ServiceCollection(ServiceCollectionABC):
|
|||||||
self.add_transient(PipeABC, pipe)
|
self.add_transient(PipeABC, pipe)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def add_singleton(self, service_type: T, service: T = None):
|
def add_singleton(self, service_type: Type[T], service: T = None):
|
||||||
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service)
|
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def add_scoped(self, service_type: T, service: Callable = None):
|
def add_scoped(self, service_type: Type[T], service: Callable = None):
|
||||||
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.scoped, service)
|
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.scoped, service)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def add_transient(self, service_type: T, service: T = None):
|
def add_transient(self, service_type: Type[T], service: T = None):
|
||||||
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.transient, service)
|
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.transient, service)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class ServiceCollectionABC(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_transient(self, service_type: T, service: T = None) -> "ServiceCollectionABC":
|
def add_transient(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC":
|
||||||
r"""Adds a service with transient lifetime
|
r"""Adds a service with transient lifetime
|
||||||
|
|
||||||
Parameter:
|
Parameter:
|
||||||
@ -61,7 +61,7 @@ class ServiceCollectionABC(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_scoped(self, service_type: T, service: T = None) -> "ServiceCollectionABC":
|
def add_scoped(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC":
|
||||||
r"""Adds a service with scoped lifetime
|
r"""Adds a service with scoped lifetime
|
||||||
|
|
||||||
Parameter:
|
Parameter:
|
||||||
@ -76,7 +76,7 @@ class ServiceCollectionABC(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_singleton(self, service_type: T, service: T = None) -> "ServiceCollectionABC":
|
def add_singleton(self, service_type: Type[T], service: T = None) -> "ServiceCollectionABC":
|
||||||
r"""Adds a service with singleton lifetime
|
r"""Adds a service with singleton lifetime
|
||||||
|
|
||||||
Parameter:
|
Parameter:
|
||||||
|
@ -138,7 +138,7 @@ class ServiceProvider(ServiceProviderABC):
|
|||||||
sb = ScopeBuilder(ServiceProvider(descriptors, self._configuration, self._database_context))
|
sb = ScopeBuilder(ServiceProvider(descriptors, self._configuration, self._database_context))
|
||||||
return sb.build()
|
return sb.build()
|
||||||
|
|
||||||
def get_service(self, service_type: T, *args, **kwargs) -> Optional[T]:
|
def get_service(self, service_type: typing.Type[T], *args, **kwargs) -> Optional[T]:
|
||||||
result = self._find_service(service_type)
|
result = self._find_service(service_type)
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
@ -157,7 +157,7 @@ class ServiceProvider(ServiceProviderABC):
|
|||||||
|
|
||||||
return implementation
|
return implementation
|
||||||
|
|
||||||
def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]:
|
def get_services(self, service_type: typing.Type[T], *args, **kwargs) -> list[Optional[T]]:
|
||||||
implementations = []
|
implementations = []
|
||||||
|
|
||||||
if typing.get_origin(service_type) != list:
|
if typing.get_origin(service_type) != list:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import functools
|
import functools
|
||||||
from abc import abstractmethod, ABC
|
from abc import abstractmethod, ABC
|
||||||
from inspect import Signature, signature
|
from inspect import Signature, signature
|
||||||
from typing import Type, Optional
|
from typing import Optional, Type
|
||||||
|
|
||||||
from cpl_core.dependency_injection.scope_abc import ScopeABC
|
from cpl_core.dependency_injection.scope_abc import ScopeABC
|
||||||
from cpl_core.type import T
|
from cpl_core.type import T
|
||||||
@ -61,7 +61,7 @@ class ServiceProviderABC(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_service(self, instance_type: T, *args, **kwargs) -> Optional[T]:
|
def get_service(self, instance_type: Type[T], *args, **kwargs) -> Optional[T]:
|
||||||
r"""Returns instance of given type
|
r"""Returns instance of given type
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
@ -76,7 +76,7 @@ class ServiceProviderABC(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_services(self, service_type: T, *args, **kwargs) -> list[Optional[T]]:
|
def get_services(self, service_type: Type[T], *args, **kwargs) -> list[Optional[T]]:
|
||||||
r"""Returns instance of given type
|
r"""Returns instance of given type
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
|
Loading…
Reference in New Issue
Block a user