diff --git a/examples/real_world/myapp/db.py b/examples/real_world/myapp/db.py index a0f252b8..88d14395 100644 --- a/examples/real_world/myapp/db.py +++ b/examples/real_world/myapp/db.py @@ -1,13 +1,13 @@ import logging -from .use_cases import ProductGateway, UnitOfWork, User, UserGateway, Product +from .use_cases import ProductGateway, Committer, User, UserGateway, Product logger = logging.getLogger(__name__) -class FakeDbConnection(UnitOfWork): +class FakeCommitter(Committer): def __init__(self): - logger.info("init FakeDbConnection as %s", self) + logger.info("init FakeCommitter as %s", self) def commit(self) -> None: logger.info("commit as %s", self) @@ -17,9 +17,9 @@ def close(self) -> None: class FakeUserGateway(UserGateway): - def __init__(self, unit_of_work: FakeDbConnection): - self.unit_of_work = unit_of_work - logger.info("init FakeUserGateway with %s", unit_of_work) + def __init__(self, committer: FakeCommitter): + self.committer = committer + logger.info("init FakeUserGateway with %s", committer) def get_user(self, user_id: int) -> User: logger.info("get_user %s as %s", user_id, self) @@ -27,9 +27,9 @@ def get_user(self, user_id: int) -> User: class FakeProductGateway(ProductGateway): - def __init__(self, unit_of_work: FakeDbConnection): - self.unit_of_work = unit_of_work - logger.info("init FakeProductGateway with %s", unit_of_work) + def __init__(self, committer: FakeCommitter): + self.committer = committer + logger.info("init FakeProductGateway with %s", committer) def add_product(self, product: Product) -> None: logger.info( diff --git a/examples/real_world/myapp/ioc.py b/examples/real_world/myapp/ioc.py index 21308ea1..cb94f63d 100644 --- a/examples/real_world/myapp/ioc.py +++ b/examples/real_world/myapp/ioc.py @@ -7,11 +7,11 @@ provide, ) from .api_client import FakeWarehouseClient -from .db import FakeDbConnection, FakeProductGateway, FakeUserGateway +from .db import FakeCommitter, FakeProductGateway, FakeUserGateway from .use_cases import ( AddProductsInteractor, ProductGateway, - UnitOfWork, + Committer, UserGateway, WarehouseClient, ) @@ -25,12 +25,12 @@ class AdaptersProvider(Provider): products = provide(FakeProductGateway, provides=ProductGateway) @provide - def connection(self) -> Iterable[FakeDbConnection]: - uow = FakeDbConnection() - yield uow - uow.close() + def connection(self) -> Iterable[FakeCommitter]: + committer = FakeCommitter() + yield committer + committer.close() - uow = alias(source=FakeDbConnection, provides=UnitOfWork) + committer = alias(source=FakeCommitter, provides=Committer) @provide(scope=Scope.APP) def warehouse(self) -> WarehouseClient: diff --git a/examples/real_world/myapp/use_cases.py b/examples/real_world/myapp/use_cases.py index fdd500ac..cd5ca5de 100644 --- a/examples/real_world/myapp/use_cases.py +++ b/examples/real_world/myapp/use_cases.py @@ -29,7 +29,7 @@ def add_product(self, product: Product) -> None: raise NotImplementedError -class UnitOfWork(Protocol): +class Committer(Protocol): @abstractmethod def commit(self) -> None: raise NotImplementedError @@ -46,12 +46,12 @@ def __init__( self, user_gateway: UserGateway, product_gateway: ProductGateway, - unit_of_work: UnitOfWork, + committer: Committer, warehouse_client: WarehouseClient, ) -> None: self.user_gateway = user_gateway self.product_gateway = product_gateway - self.unit_of_work = unit_of_work + self.committer = committer self.warehouse_client = warehouse_client def __call__(self, user_id: int): @@ -63,4 +63,4 @@ def __call__(self, user_id: int): self.product_gateway.add_product(product) product2 = Product(user_id, self.warehouse_client.next_product()) self.product_gateway.add_product(product2) - self.unit_of_work.commit() + self.committer.commit() diff --git a/examples/real_world/tests/test_add_products.py b/examples/real_world/tests/test_add_products.py index 2c6b5169..e602cf94 100644 --- a/examples/real_world/tests/test_add_products.py +++ b/examples/real_world/tests/test_add_products.py @@ -9,8 +9,8 @@ from myapp.ioc import InteractorProvider from myapp.use_cases import ( AddProductsInteractor, + Committer, ProductGateway, - UnitOfWork, User, UserGateway, WarehouseClient, @@ -26,7 +26,7 @@ # app dependency logic class AdaptersProvider(Provider): - scope=Scope.APP + scope = Scope.APP @provide def users(self) -> UserGateway: @@ -41,10 +41,10 @@ def products(self) -> ProductGateway: return gateway @provide - def uow(self) -> UnitOfWork: - uow = Mock() - uow.commit = Mock() - return uow + def committer(self) -> Committer: + committer = Mock() + committer.commit = Mock() + return committer @provide def warehouse(self) -> WarehouseClient: @@ -63,4 +63,4 @@ def container(): def test_interactor(container): interactor = container.get(AddProductsInteractor) interactor(1) - container.get(UnitOfWork).commit.assert_called_once_with() + container.get(Committer).commit.assert_called_once_with()