Coverage for src / lexigram / admin / web / contributor.py: 0%
14 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-11 02:25 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-11 02:25 +0800
1"""Admin web contributor for route and middleware registration."""
3from __future__ import annotations
5from typing import TYPE_CHECKING, Any
7if TYPE_CHECKING:
8 from lexigram.contracts.core.container import ( # type: ignore[import-untyped]
9 ContainerResolverProtocol,
10 )
13class AdminWebContributor:
14 """Web contributor for the admin package.
16 Resolves and delegates to the AdminBundle's mount_to_app method
17 if available. Does not contribute controllers or middleware directly;
18 the bundle handles all mounting.
19 """
21 @property
22 def contributor_id(self) -> str:
23 """Return unique identifier for this contributor.
25 Returns:
26 The string "admin".
27 """
28 return "admin"
30 def get_controllers(self) -> list[type[Any]]:
31 """Return controllers contributed by the admin package.
33 Admin uses the bundle pattern and does not contribute controllers directly.
35 Returns:
36 Empty list.
37 """
38 return []
40 def get_middleware(self) -> list[type[Any]]:
41 """Return middleware contributed by the admin package.
43 Admin uses the bundle pattern and does not contribute middleware directly.
45 Returns:
46 Empty list.
47 """
48 return []
50 async def mount_to_app(
51 self, app: Any, container: ContainerResolverProtocol
52 ) -> None:
53 """Mount admin routes to the web application.
55 Resolves the admin_bundle service (bypassing visibility checks)
56 and delegates to its mount_to_app method if available.
58 Args:
59 app: The ASGI application (typically Starlette).
60 container: DI container for resolving the admin bundle.
61 """
62 admin_bundle = await container.resolve("admin_bundle", bypass_visibility=True)
63 if admin_bundle and hasattr(admin_bundle, "mount_to_app"):
64 await admin_bundle.mount_to_app(app, container)