Added logic to support global service provider #148
This commit is contained in:
@@ -3,8 +3,9 @@ from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.dependency_injection.scope import Scope
|
||||
from test_service_service import TestService
|
||||
from di_tester_service import DITesterService
|
||||
from di.static_test import StaticTest
|
||||
from di.test_service_service import TestService
|
||||
from di.di_tester_service import DITesterService
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
@@ -15,7 +16,7 @@ class Application(ApplicationABC):
|
||||
def _part_of_scoped(self):
|
||||
ts: TestService = self._services.get_service(TestService)
|
||||
ts.run()
|
||||
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
|
||||
@@ -26,10 +27,10 @@ class Application(ApplicationABC):
|
||||
ts.run()
|
||||
dit: DITesterService = scope.service_provider.get_service(DITesterService)
|
||||
dit.run()
|
||||
|
||||
#Console.write_line('Disposed:')
|
||||
#ts1: TestService = scope1.service_provider.get_service(TestService)
|
||||
#ts1.run()
|
||||
|
||||
# Console.write_line('Disposed:')
|
||||
# ts1: TestService = scope1.service_provider.get_service(TestService)
|
||||
# ts1.run()
|
||||
|
||||
with self._services.create_scope() as scope:
|
||||
Console.write_line('Scope2')
|
||||
@@ -37,6 +38,9 @@ class Application(ApplicationABC):
|
||||
ts.run()
|
||||
dit: DITesterService = scope.service_provider.get_service(DITesterService)
|
||||
dit.run()
|
||||
|
||||
|
||||
Console.write_line('Global')
|
||||
self._part_of_scoped()
|
||||
StaticTest.test()
|
||||
with self._services.create_scope() as scope:
|
||||
StaticTest.test()
|
||||
|
@@ -1,5 +1,5 @@
|
||||
from cpl_core.console.console import Console
|
||||
from test_service_service import TestService
|
||||
from di.test_service_service import TestService
|
||||
|
||||
|
||||
class DITesterService:
|
||||
|
@@ -2,8 +2,8 @@ from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironment
|
||||
from test_service_service import TestService
|
||||
from di_tester_service import DITesterService
|
||||
from di.test_service_service import TestService
|
||||
from di.di_tester_service import DITesterService
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
11
tests/custom/di/src/di/static_test.py
Normal file
11
tests/custom/di/src/di/static_test.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProvider, ServiceProviderABC
|
||||
from di.test_service_service import TestService
|
||||
|
||||
|
||||
class StaticTest:
|
||||
|
||||
@staticmethod
|
||||
@ServiceProvider.inject
|
||||
def test(services: ServiceProviderABC, config: ConfigurationABC, t1: TestService):
|
||||
t1.run()
|
Reference in New Issue
Block a user