Added logic to handle async applicationBase

This commit is contained in:
2021-11-14 12:16:50 +01:00
parent 98e343a108
commit 4b829cc484
15 changed files with 181 additions and 5 deletions

View File

View File

View File

@@ -0,0 +1,15 @@
{
"TimeFormatSettings": {
"DateFormat": "%Y-%m-%d",
"TimeFormat": "%H:%M:%S",
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
},
"LoggingSettings": {
"Path": "logs/",
"Filename": "log_$start_time.log",
"ConsoleLogLevel": "ERROR",
"FileLogLevel": "WARN"
}
}

View File

@@ -0,0 +1,9 @@
{
"WorkspaceSettings": {
"DefaultProject": "async",
"Projects": {
"async": "src/async/async.json"
},
"Scripts": {}
}
}

View File

@@ -0,0 +1 @@
# imports:

View File

@@ -0,0 +1,16 @@
from cpl_core.application import ApplicationABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceProviderABC
class Application(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
ApplicationABC.__init__(self, config, services)
async def configure(self):
pass
async def main(self):
Console.write_line('Hello World')

View File

@@ -0,0 +1,43 @@
{
"ProjectSettings": {
"Name": "async",
"Version": {
"Major": "0",
"Minor": "0",
"Micro": "0"
},
"Author": "",
"AuthorEmail": "",
"Description": "",
"LongDescription": "",
"URL": "",
"CopyrightDate": "",
"CopyrightName": "",
"LicenseName": "",
"LicenseDescription": "",
"Dependencies": [
"sh_cpl>=2021.10.0.post1"
],
"PythonVersion": ">=3.9.2",
"PythonPath": {
"linux": ""
},
"Classifiers": []
},
"BuildSettings": {
"ProjectType": "console",
"SourcePath": "",
"OutputPath": "../../dist",
"Main": "async.main",
"EntryPoint": "async",
"IncludePackageData": false,
"Included": [],
"Excluded": [
"*/__pycache__",
"*/logs",
"*/tests"
],
"PackageData": {},
"ProjectReferences": []
}
}

View File

@@ -0,0 +1,17 @@
import asyncio
from cpl_core.application import ApplicationBuilder
from application import Application
from startup import Startup
async def main():
app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup)
app = await app_builder.build_async()
await app.run_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

View File

@@ -0,0 +1,16 @@
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
class Startup(StartupABC):
def __init__(self):
StartupABC.__init__(self)
async def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
return configuration
async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
return services.build_service_provider()

View File

@@ -0,0 +1 @@
# imports:

View File

@@ -30,9 +30,9 @@ class Application(ApplicationABC):
b = t.service_provider
scope1.dispose()
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()
Console.write_line('Scope2')
scope2: Scope = self._services.create_scope()