Source code for cadrumo.application.modelo.work_unit_repository
"""Explicit lifetime binding for Modelo work-unit catalogue persistence.The domain owns the repository protocol and persistence owns its concreteimplementation. Application operations that need to capture a catalogue bindonly the factory shape declared here; executable hosts compose the concreteadapter for their own lifetime."""from__future__importannotationsfromcollections.abcimportGeneratorfromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfromtypingimportProtocolfrom...core.errors.hierarchyimportInternalInvariantErrorfrom...domain.modelos.work_unit_repositoryimportWorkUnitCatalogueRepositoryProtocol
[docs]classWorkUnitCatalogueRepositoryFactory(Protocol):"""Construct the repository port for one resolved profile bucket."""def__call__(self,*,bucket_id:str)->WorkUnitCatalogueRepositoryProtocol:"""Return the repository bound to ``bucket_id``."""...
[docs]@contextmanagerdefbind_work_unit_catalogue_repository_factory(factory:WorkUnitCatalogueRepositoryFactory,)->Generator[WorkUnitCatalogueRepositoryFactory]:"""Bind one outward-composed repository factory for the host context."""token=_BOUND_WORK_UNIT_CATALOGUE_REPOSITORY_FACTORY.set(factory)try:yieldfactoryfinally:_BOUND_WORK_UNIT_CATALOGUE_REPOSITORY_FACTORY.reset(token)
[docs]defwork_unit_catalogue_repository(*,bucket_id:str)->WorkUnitCatalogueRepositoryProtocol:"""Resolve the explicitly composed repository for ``bucket_id``."""try:factory=_BOUND_WORK_UNIT_CATALOGUE_REPOSITORY_FACTORY.get()exceptLookupErroraserror:raiseInternalInvariantError("work-unit catalogue persistence has not been composed")fromerrorreturnfactory(bucket_id=bucket_id)