File tree Expand file tree Collapse file tree 9 files changed +39
-26
lines changed
Expand file tree Collapse file tree 9 files changed +39
-26
lines changed Original file line number Diff line number Diff line change 22 "cells" : [
33 {
44 "cell_type" : " code" ,
5- "execution_count" : 1 ,
5+ "execution_count" : null ,
66 "metadata" : {},
77 "outputs" : [],
88 "source" : [
1212 },
1313 {
1414 "cell_type" : " code" ,
15- "execution_count" : 2 ,
15+ "execution_count" : null ,
1616 "metadata" : {},
1717 "outputs" : [],
1818 "source" : [
19- " email_service = await services.get(EmailService)\n " ,
19+ " service_provider = services.build_service_provider()"
20+ ]
21+ },
22+ {
23+ "cell_type" : " code" ,
24+ "execution_count" : null ,
25+ "metadata" : {},
26+ "outputs" : [],
27+ "source" : [
28+ " email_service = await service_provider.get_required_service(EmailService)\n " ,
2029 " await email_service.send_email()"
2130 ]
2231 }
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ dependencies = [
1111 " pydantic>=2.12.5" ,
1212 " pydantic-settings[azure-key-vault]>=2.12.0" ,
1313 " sqlmodel>=0.0.31" ,
14- " wirio>=0.7 .0" ,
14+ " wirio>=0.8 .0" ,
1515]
1616
1717[dependency-groups ]
Original file line number Diff line number Diff line change 55
66
77async def main () -> None :
8- async with services :
9- email_service = await services . get (EmailService )
8+ async with services . build_service_provider () as service_provider :
9+ email_service = await service_provider . get_required_service (EmailService )
1010 await email_service .send_email ()
1111
1212
Original file line number Diff line number Diff line change 11from fastapi import FastAPI
2- from wirio .service_container import ServiceContainer
2+ from wirio .service_collection import ServiceCollection
33
44from python_template .api .application_settings import ApplicationSettings
55from python_template .api .service_collection_extensions import (
2424app = FastAPI (openapi_url = openapi_url )
2525app .include_router (product_router )
2626
27- services = ServiceContainer ()
27+ services = ServiceCollection ()
2828application_settings = ApplicationSettings () # ty:ignore[missing-argument]
2929services .add_singleton (ApplicationSettings , application_settings )
3030add_observability (services , application_settings )
Original file line number Diff line number Diff line change 99 async_sessionmaker ,
1010 create_async_engine ,
1111)
12- from wirio .service_container import ServiceContainer
12+ from wirio .service_collection import ServiceCollection
1313
1414from python_template .api .application_settings import ApplicationSettings
1515from python_template .common .application_environment import ApplicationEnvironment
1616
1717
1818def add_observability (
19- services : ServiceContainer , application_settings : ApplicationSettings
19+ services : ServiceCollection , application_settings : ApplicationSettings
2020) -> None :
2121 def inject_logging () -> Logger :
2222 return logging .getLogger (__name__ )
@@ -32,7 +32,7 @@ def inject_logging() -> Logger:
3232 )
3333
3434
35- def add_sqlmodel (services : ServiceContainer ) -> None :
35+ def add_sqlmodel (services : ServiceCollection ) -> None :
3636 def inject_async_engine (application_settings : ApplicationSettings ) -> AsyncEngine :
3737 return create_async_engine (application_settings .postgresql_connection_string )
3838
Original file line number Diff line number Diff line change 11from collections .abc import AsyncGenerator
22
33import pytest
4- from wirio .service_container import ServiceContainer
4+ from wirio .service_provider import ServiceProvider
55
66from python_template .api .main import services
77
88
99@pytest .fixture
10- async def services_fixture () -> AsyncGenerator [ServiceContainer ]:
11- async with services :
12- yield services
10+ async def service_provider () -> AsyncGenerator [ServiceProvider ]:
11+ async with services . build_service_provider () as service_provider :
12+ yield service_provider
Original file line number Diff line number Diff line change 11import pytest
22from sqlalchemy .ext .asyncio import AsyncSession
3- from wirio .service_container import ServiceContainer
3+ from wirio .service_provider import ServiceProvider
44
55from python_template .api .workflows .products .discontinue_product .discontinue_product_request import (
66 DiscontinueProductRequest ,
1414
1515class TestDiscontinueProductWorkflow :
1616 @pytest .fixture (autouse = True )
17- async def setup (self , services_fixture : ServiceContainer ) -> None :
18- self .workflow = await services_fixture .get (DiscontinueProductWorkflow )
19- self .sql_session = await services_fixture .get (AsyncSession )
17+ async def setup (self , service_provider : ServiceProvider ) -> None :
18+ self .workflow = await service_provider .get_required_service (
19+ DiscontinueProductWorkflow
20+ )
21+ self .sql_session = await service_provider .get_required_service (AsyncSession )
2022
2123 async def test_discontinue_product (self ) -> None :
2224 product = ProductBuilder ().build ()
Original file line number Diff line number Diff line change 11import pytest
2- from wirio .service_container import ServiceContainer
2+ from wirio .service_provider import ServiceProvider
33
44from python_template .api .workflows .products .publish_product .publish_product_workflow import (
55 PublishProductWorkflow ,
1111
1212class TestPublishProductWorkflow :
1313 @pytest .fixture (autouse = True )
14- async def setup (self , services_fixture : ServiceContainer ) -> None :
15- self .workflow = await services_fixture .get (PublishProductWorkflow )
14+ async def setup (self , service_provider : ServiceProvider ) -> None :
15+ self .workflow = await service_provider .get_required_service (
16+ PublishProductWorkflow
17+ )
1618
1719 async def test_publish_product (self ) -> None :
1820 request = PublishProductRequestBuilder ().build ()
You can’t perform that action at this time.
0 commit comments