#166 #167

Merged
edraft merged 3 commits from #166 into 2023.4 2023-04-11 14:49:22 +02:00
6 changed files with 13 additions and 13 deletions

View File

@ -294,7 +294,7 @@ class Configuration(ConfigurationABC):
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
def create_console_argument(

View File

@ -77,7 +77,7 @@ class ConfigurationABC(ABC):
pass
@abstractmethod
def add_configuration(self, key_type: T, value: any):
def add_configuration(self, key_type: Type[T], value: any):
r"""Add configuration object
Parameter:

View File

@ -61,15 +61,15 @@ class ServiceCollection(ServiceCollectionABC):
self.add_transient(PipeABC, pipe)
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)
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)
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)
return self

View File

@ -46,7 +46,7 @@ class ServiceCollectionABC(ABC):
pass
@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
Parameter:
@ -61,7 +61,7 @@ class ServiceCollectionABC(ABC):
pass
@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
Parameter:
@ -76,7 +76,7 @@ class ServiceCollectionABC(ABC):
pass
@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
Parameter:

View File

@ -138,7 +138,7 @@ class ServiceProvider(ServiceProviderABC):
sb = ScopeBuilder(ServiceProvider(descriptors, self._configuration, self._database_context))
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)
if result is None:
@ -157,7 +157,7 @@ class ServiceProvider(ServiceProviderABC):
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 = []
if typing.get_origin(service_type) != list:

View File

@ -1,7 +1,7 @@
import functools
from abc import abstractmethod, ABC
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.type import T
@ -61,7 +61,7 @@ class ServiceProviderABC(ABC):
pass
@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
Parameter
@ -76,7 +76,7 @@ class ServiceProviderABC(ABC):
pass
@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
Parameter