|
16 | 16 | ) |
17 | 17 | from python_template.common.application_environment import ApplicationEnvironment |
18 | 18 |
|
19 | | -openapi_url = ( |
20 | | - "/openapi.json" |
21 | | - if ApplicationEnvironment.get_current() != ApplicationEnvironment.PRODUCTION |
22 | | - else None |
23 | | -) |
24 | | -app = FastAPI(openapi_url=openapi_url) |
25 | | -app.include_router(product_router) |
26 | 19 |
|
27 | | -services = ServiceCollection() |
28 | | -application_settings = ApplicationSettings() # ty:ignore[missing-argument] |
29 | | -services.add_singleton(ApplicationSettings, application_settings) |
30 | | -add_observability(services, application_settings) |
31 | | -add_sqlmodel(services) |
32 | | -services.add_transient(EmailService) |
33 | | -services.add_transient(PublishProductWorkflow) |
34 | | -services.add_transient(DiscontinueProductWorkflow) |
| 20 | +def configure_services() -> ServiceCollection: |
| 21 | + services = ServiceCollection() |
| 22 | + application_settings = ApplicationSettings() # ty:ignore[missing-argument] |
| 23 | + services.add_singleton(ApplicationSettings, application_settings) |
| 24 | + add_observability(services, application_settings) |
| 25 | + add_sqlmodel(services) |
| 26 | + services.add_transient(EmailService) |
| 27 | + services.add_transient(PublishProductWorkflow) |
| 28 | + services.add_transient(DiscontinueProductWorkflow) |
| 29 | + return services |
| 30 | + |
| 31 | + |
| 32 | +def create_app() -> FastAPI: |
| 33 | + openapi_url = ( |
| 34 | + "/openapi.json" |
| 35 | + if ApplicationEnvironment.get_current() != ApplicationEnvironment.PRODUCTION |
| 36 | + else None |
| 37 | + ) |
| 38 | + app = FastAPI(openapi_url=openapi_url) |
| 39 | + app.include_router(product_router) |
| 40 | + return app |
| 41 | + |
| 42 | + |
| 43 | +app = create_app() |
| 44 | +services = configure_services() |
35 | 45 | services.configure_fastapi(app) |
0 commit comments