Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 13. Dependency Injection use same uow concurrently in entrypoint? #69

Closed
wyg031113 opened this issue Apr 17, 2023 · 2 comments
Closed

Comments

@wyg031113
Copy link

wyg031113 commented Apr 17, 2023

booststrap script bind same uow to all handlers? Every request use same uow object. Should we create uow on every http request/or every event/every command ?
UoW is consistent boundary, it commit changes after one handler. but now, concurrent committing concurrently will broke it?


def bootstrap(
    start_orm: bool = True,
    uow: unit_of_work.AbstractUnitOfWork = unit_of_work.SqlAlchemyUnitOfWork(), #sameobject
    notifications: AbstractNotifications = None,
    publish: Callable = redis_eventpublisher.publish,
) -> messagebus.MessageBus:

class MessageBus:
    def __init__(
        self,
        uow: unit_of_work.AbstractUnitOfWork,
        event_handlers: Dict[Type[events.Event], List[Callable]],
        command_handlers: Dict[Type[commands.Command], Callable],
    ):
        self.uow = uow  #sameobject
        self.event_handlers = event_handlers
        self.command_handlers = command_handlers

@hjwp
Copy link
Contributor

hjwp commented Apr 27, 2023

yes, you shouldn't use this exact code if you're working in a multithreaded environment.

@hjwp hjwp closed this as completed Apr 27, 2023
@hjwp
Copy link
Contributor

hjwp commented Apr 27, 2023

see also the discussion here! #23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants