Coverage for src/lexigram/admin/web/contributor.py: 0%
14 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 23:18 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 23:18 +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.di import ContainerResolverProtocol
11class AdminWebContributor:
12 """Web contributor for the admin package.
14 Resolves and delegates to the AdminBundle's mount_to_app method
15 if available. Does not contribute controllers or middleware directly;
16 the bundle handles all mounting.
17 """
19 @property
20 def contributor_id(self) -> str:
21 """Return unique identifier for this contributor.
23 Returns:
24 The string "admin".
25 """
26 return "admin"
28 def get_controllers(self) -> list[type[Any]]:
29 """Return controllers contributed by the admin package.
31 Admin uses the bundle pattern and does not contribute controllers directly.
33 Returns:
34 Empty list.
35 """
36 return []
38 def get_middleware(self) -> list[type[Any]]:
39 """Return middleware contributed by the admin package.
41 Admin uses the bundle pattern and does not contribute middleware directly.
43 Returns:
44 Empty list.
45 """
46 return []
48 async def mount_to_app(
49 self, app: Any, container: ContainerResolverProtocol
50 ) -> None:
51 """Mount admin routes to the web application.
53 Resolves the admin_bundle service (bypassing visibility checks)
54 and delegates to its mount_to_app method if available.
56 Args:
57 app: The ASGI application (typically Starlette).
58 container: DI container for resolving the admin bundle.
59 """
60 admin_bundle = await container.resolve("admin_bundle", bypass_visibility=True)
61 if admin_bundle and hasattr(admin_bundle, "mount_to_app"):
62 await admin_bundle.mount_to_app(app, container)