Moved tests to src & added add scoped logic
This commit is contained in:
		| @@ -59,9 +59,13 @@ class ServiceCollection(ServiceCollectionABC): | ||||
|             self._add_descriptor(impl, ServiceLifetimeEnum.singleton) | ||||
|  | ||||
|     def add_scoped(self, service_type: Type, service: Callable = None): | ||||
|         raise Exception('Not implemented') | ||||
|         if service is not None: | ||||
|             self._add_descriptor(service, ServiceLifetimeEnum.scoped) | ||||
|         else: | ||||
|             self._add_descriptor(service_type, ServiceLifetimeEnum.scoped) | ||||
|          | ||||
|  | ||||
|     def add_transient(self, service_type: Union[type], service: Union[type] = None): | ||||
|     def add_transient(self, service_type: type, service: type = None): | ||||
|         if service is not None: | ||||
|             self._add_descriptor(service, ServiceLifetimeEnum.transient) | ||||
|         else: | ||||
|   | ||||
| @@ -31,7 +31,7 @@ class ServiceProvider(ServiceProviderABC): | ||||
|         self._configuration: ConfigurationABC = config | ||||
|         self._database_context = db_context | ||||
|  | ||||
|     def _find_service(self, service_type: type) -> [ServiceDescriptor]: | ||||
|     def _find_service(self, service_type: type) -> ServiceDescriptor: | ||||
|         for descriptor in self._service_descriptors: | ||||
|             if descriptor.service_type == service_type or issubclass(descriptor.service_type, service_type): | ||||
|                 return descriptor | ||||
| @@ -85,7 +85,7 @@ class ServiceProvider(ServiceProviderABC): | ||||
|  | ||||
|         return service_type(*params) | ||||
|  | ||||
|     def get_service(self, service_type: type) -> Optional[Callable[object]]: | ||||
|     def get_service(self, service_type: type) -> Optional[Callable]: | ||||
|         result = self._find_service(service_type) | ||||
|  | ||||
|         if result is None: | ||||
|   | ||||
| @@ -26,7 +26,7 @@ class ServiceProviderABC(ABC): | ||||
|         pass | ||||
|  | ||||
|     @abstractmethod | ||||
|     def get_service(self, instance_type: Type) -> Optional[Callable[object]]: | ||||
|     def get_service(self, instance_type: Type) -> Optional[Callable]: | ||||
|         r"""Returns instance of given type | ||||
|  | ||||
|         Parameter | ||||
|   | ||||
		Reference in New Issue
	
	Block a user