Updated docs
This commit is contained in:
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -11,7 +11,6 @@ from di.tester import Tester
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
@@ -24,20 +23,20 @@ class Application(ApplicationABC):
|
||||
|
||||
def main(self):
|
||||
with self._services.create_scope() as scope:
|
||||
Console.write_line('Scope1')
|
||||
Console.write_line("Scope1")
|
||||
ts: TestService = scope.service_provider.get_service(TestService)
|
||||
ts.run()
|
||||
dit: DITesterService = scope.service_provider.get_service(DITesterService)
|
||||
dit.run()
|
||||
|
||||
with self._services.create_scope() as scope:
|
||||
Console.write_line('Scope2')
|
||||
Console.write_line("Scope2")
|
||||
ts: TestService = scope.service_provider.get_service(TestService)
|
||||
ts.run()
|
||||
dit: DITesterService = scope.service_provider.get_service(DITesterService)
|
||||
dit.run()
|
||||
|
||||
Console.write_line('Global')
|
||||
Console.write_line("Global")
|
||||
self._part_of_scoped()
|
||||
StaticTest.test()
|
||||
|
||||
|
@@ -3,10 +3,9 @@ from di.test_service import TestService
|
||||
|
||||
|
||||
class DITesterService:
|
||||
|
||||
def __init__(self, ts: TestService):
|
||||
self._ts = ts
|
||||
|
||||
|
||||
def run(self):
|
||||
Console.write_line('DIT: ')
|
||||
Console.write_line("DIT: ")
|
||||
self._ts.run()
|
||||
|
@@ -10,5 +10,5 @@ def main():
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@@ -11,19 +11,22 @@ from di.tester import Tester
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
def configure_configuration(
|
||||
self, configuration: ConfigurationABC, environment: ApplicationEnvironment
|
||||
) -> ConfigurationABC:
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
def configure_services(
|
||||
self, services: ServiceCollectionABC, environment: ApplicationEnvironment
|
||||
) -> ServiceProviderABC:
|
||||
services.add_scoped(TestService)
|
||||
services.add_scoped(DITesterService)
|
||||
|
||||
services.add_singleton(TestABC, Test1Service)
|
||||
services.add_singleton(TestABC, Test2Service)
|
||||
services.add_singleton(Tester)
|
||||
|
||||
|
||||
return services.build_service_provider()
|
||||
|
@@ -4,7 +4,6 @@ from di.test_service import TestService
|
||||
|
||||
|
||||
class StaticTest:
|
||||
|
||||
@staticmethod
|
||||
@ServiceProvider.inject
|
||||
def test(services: ServiceProviderABC, config: ConfigurationABC, t1: TestService):
|
||||
|
@@ -5,9 +5,8 @@ from di.test_abc import TestABC
|
||||
|
||||
|
||||
class Test1Service(TestABC):
|
||||
|
||||
def __init__(self):
|
||||
TestABC.__init__(self, String.random_string(string.ascii_lowercase, 8))
|
||||
|
||||
def run(self):
|
||||
Console.write_line(f'Im {self._name}')
|
||||
Console.write_line(f"Im {self._name}")
|
||||
|
@@ -5,9 +5,8 @@ from di.test_abc import TestABC
|
||||
|
||||
|
||||
class Test2Service(TestABC):
|
||||
|
||||
def __init__(self):
|
||||
TestABC.__init__(self, String.random_string(string.ascii_lowercase, 8))
|
||||
|
||||
def run(self):
|
||||
Console.write_line(f'Im {self._name}')
|
||||
Console.write_line(f"Im {self._name}")
|
||||
|
@@ -2,9 +2,8 @@ from abc import ABC
|
||||
|
||||
|
||||
class TestABC(ABC):
|
||||
|
||||
def __init__(self, name: str):
|
||||
self._name = name
|
||||
|
||||
def __repr__(self):
|
||||
return f'<{type(self).__name__} {self._name}>'
|
||||
return f"<{type(self).__name__} {self._name}>"
|
||||
|
@@ -5,9 +5,8 @@ from cpl_core.utils.string import String
|
||||
|
||||
|
||||
class TestService:
|
||||
|
||||
def __init__(self):
|
||||
self._name = String.random_string(string.ascii_lowercase, 8)
|
||||
|
||||
def run(self):
|
||||
Console.write_line(f'Im {self._name}')
|
||||
Console.write_line(f"Im {self._name}")
|
||||
|
@@ -3,7 +3,6 @@ from di.test_abc import TestABC
|
||||
|
||||
|
||||
class Tester:
|
||||
|
||||
def __init__(self, t1: TestABC, t2: TestABC, t3: list[TestABC]):
|
||||
Console.write_line('Tester:')
|
||||
Console.write_line("Tester:")
|
||||
Console.write_line(t1, t2, t3)
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
Reference in New Issue
Block a user