Added ServiceProvider

This commit is contained in:
2020-11-22 14:15:39 +01:00
parent e921338fe6
commit bcfe6f2de4
10 changed files with 210 additions and 26 deletions

View File

@@ -0,0 +1,30 @@
from abc import ABC, abstractmethod
from collections import Callable
from typing import Type
from sh_edraft.service.base.service_base import ServiceBase
from sh_edraft.service.model.provide_state import ProvideState
class ProviderBase(ABC):
@abstractmethod
def __init__(self):
self._transient_services: list[ProvideState] = []
self._scoped_services: list[ProvideState] = []
self._singleton_services: list[ServiceBase] = []
@abstractmethod
def add_transient(self, service: Type[ServiceBase], *args): pass
@abstractmethod
def add_scoped(self, service: Type[ServiceBase], *args): pass
@abstractmethod
def add_singleton(self, service: Type[ServiceBase], *args): pass
@abstractmethod
def get_service(self, instance_type: type) -> Callable[ServiceBase]: pass
@abstractmethod
def remove_service(self, instance_type: type): pass