python-platform 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_platform/__init__.py +445 -0
- python_platform/application/__init__.py +6 -0
- python_platform/application/build_spec.py +37 -0
- python_platform/application/builder.py +260 -0
- python_platform/application/composition.py +219 -0
- python_platform/application/runtime.py +546 -0
- python_platform/application/runtime_hooks.py +327 -0
- python_platform/application/state.py +216 -0
- python_platform/application_services/__init__.py +54 -0
- python_platform/application_services/catalog.py +500 -0
- python_platform/application_services/contracts.py +188 -0
- python_platform/application_services/dispatcher.py +423 -0
- python_platform/application_services/errors.py +89 -0
- python_platform/application_services/execution.py +199 -0
- python_platform/application_services/interceptors.py +44 -0
- python_platform/application_services/invocation.py +427 -0
- python_platform/application_services/policies.py +46 -0
- python_platform/application_services/seeding.py +72 -0
- python_platform/application_services/signature.py +49 -0
- python_platform/application_services/validation.py +84 -0
- python_platform/auditing/__init__.py +12 -0
- python_platform/auditing/contracts.py +39 -0
- python_platform/auditing/control.py +48 -0
- python_platform/auditing/sqlalchemy/__init__.py +6 -0
- python_platform/auditing/sqlalchemy/migrations/0001_platform_auditing.py +45 -0
- python_platform/auditing/sqlalchemy/migrations/__init__.py +1 -0
- python_platform/auditing/sqlalchemy/models.py +31 -0
- python_platform/auditing/sqlalchemy/module.py +32 -0
- python_platform/auditing/sqlalchemy/store.py +63 -0
- python_platform/authorization/__init__.py +38 -0
- python_platform/authorization/catalog.py +63 -0
- python_platform/authorization/contracts.py +241 -0
- python_platform/authorization/definition_discovery.py +81 -0
- python_platform/authorization/definitions.py +43 -0
- python_platform/authorization/errors.py +40 -0
- python_platform/background_execution/__init__.py +15 -0
- python_platform/background_execution/application.py +41 -0
- python_platform/background_execution/child.py +123 -0
- python_platform/background_execution/contracts.py +39 -0
- python_platform/background_execution/lifecycle.py +22 -0
- python_platform/background_execution/local.py +127 -0
- python_platform/background_execution/locks.py +31 -0
- python_platform/background_execution/management.py +17 -0
- python_platform/background_execution/module.py +10 -0
- python_platform/background_execution/permissions.py +14 -0
- python_platform/background_execution/processes.py +331 -0
- python_platform/background_jobs/__init__.py +31 -0
- python_platform/background_jobs/catalog.py +287 -0
- python_platform/background_jobs/contracts.py +202 -0
- python_platform/background_jobs/errors.py +28 -0
- python_platform/background_jobs/execution.py +201 -0
- python_platform/background_jobs/pgqueuer/UPSTREAM_LICENSE.txt +21 -0
- python_platform/background_jobs/pgqueuer/__init__.py +6 -0
- python_platform/background_jobs/pgqueuer/enqueue.py +82 -0
- python_platform/background_jobs/pgqueuer/migrations/0001_pgqueuer_1_3_2.py +63 -0
- python_platform/background_jobs/pgqueuer/migrations/__init__.py +1 -0
- python_platform/background_jobs/pgqueuer/module.py +102 -0
- python_platform/background_jobs/pgqueuer/options.py +70 -0
- python_platform/background_jobs/pgqueuer/runtime.py +479 -0
- python_platform/background_jobs/pgqueuer/sql/pgqueuer_1_3_2_install.sql +118 -0
- python_platform/background_jobs/pgqueuer/supervision.py +201 -0
- python_platform/background_workers/__init__.py +22 -0
- python_platform/background_workers/catalog.py +96 -0
- python_platform/background_workers/contracts.py +124 -0
- python_platform/background_workers/errors.py +20 -0
- python_platform/background_workers/execution.py +133 -0
- python_platform/background_workers/runtime.py +203 -0
- python_platform/caching/__init__.py +11 -0
- python_platform/caching/catalog.py +73 -0
- python_platform/caching/contracts.py +73 -0
- python_platform/caching/errors.py +20 -0
- python_platform/cli/__init__.py +87 -0
- python_platform/cli/errors.py +5 -0
- python_platform/cli/project.py +69 -0
- python_platform/cli/runtime.py +68 -0
- python_platform/configuration/__init__.py +21 -0
- python_platform/configuration/composition.py +65 -0
- python_platform/configuration/contracts.py +68 -0
- python_platform/configuration/dotenv_source.py +51 -0
- python_platform/configuration/environment_source.py +38 -0
- python_platform/configuration/immutability.py +124 -0
- python_platform/configuration/input_shape.py +58 -0
- python_platform/configuration/merge.py +103 -0
- python_platform/configuration/root.py +215 -0
- python_platform/configuration/sources.py +519 -0
- python_platform/configuration/values.py +427 -0
- python_platform/configuration/yaml_source.py +51 -0
- python_platform/developer_kit/__init__.py +1 -0
- python_platform/developer_kit/generation.py +182 -0
- python_platform/developer_kit/project_metadata.py +45 -0
- python_platform/developer_kit/source.py +53 -0
- python_platform/developer_kit/templates/module/cookiecutter.json +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/cache.py.jinja +10 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/events.py.jinja +24 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/integration.py.jinja +46 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/module.py.jinja +29 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/options.py.jinja +8 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/orders.py.jinja +81 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application/tasks.py.jinja +86 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application_contracts/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application_contracts/module.py.jinja +10 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/application_contracts/orders.py.jinja +36 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/module.py.jinja +10 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/orders.py.jinja +57 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/repository.py.jinja +12 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/seeding.py.jinja +19 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain/settings.py.jinja +16 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain_shared/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain_shared/definitions.py.jinja +24 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain_shared/module.py.jinja +7 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/domain_shared/permissions.py.jinja +15 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/http_api/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/http_api/files.py.jinja +74 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/http_api/module.py.jinja +58 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/http_api/realtime.py.jinja +37 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/migrations/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/models.py.jinja +26 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/module.py.jinja +32 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/sqlalchemy/repository.py.jinja +49 -0
- python_platform/developer_kit/templates/module/{{cookiecutter.module_name}}/tests/test_domain.py.jinja +18 -0
- python_platform/developer_kit/templates/project/cookiecutter.json +6 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/.dockerignore +8 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/.env.jinja +13 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/.gitignore +6 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/.python-version +1 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/Dockerfile +22 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/README.md +86 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/app.yaml.jinja +16 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/compose.dev.yaml.jinja +24 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/compose.production.yaml.jinja +13 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/pyproject.toml.jinja +28 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/src/host/__init__.py.jinja +1 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/src/host/main.py.jinja +52 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/src/host/module.py.jinja +38 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/tests/conftest.py.jinja +8 -0
- python_platform/developer_kit/templates/project/{{cookiecutter.project_name}}/tests/host/test_http.py.jinja +101 -0
- python_platform/developer_kit/wiring.py +85 -0
- python_platform/diagnostics/__init__.py +23 -0
- python_platform/diagnostics/journal.py +174 -0
- python_platform/diagnostics/model.py +83 -0
- python_platform/diagnostics/source.py +25 -0
- python_platform/distributed_lock/__init__.py +6 -0
- python_platform/distributed_lock/contracts.py +20 -0
- python_platform/distributed_lock/options.py +19 -0
- python_platform/domain/__init__.py +13 -0
- python_platform/domain/aggregates.py +64 -0
- python_platform/domain/entities.py +33 -0
- python_platform/domain/errors.py +12 -0
- python_platform/domain/value_objects.py +31 -0
- python_platform/errors/__init__.py +75 -0
- python_platform/errors/base.py +13 -0
- python_platform/errors/business.py +53 -0
- python_platform/errors/configuration.py +119 -0
- python_platform/errors/diagnostics.py +12 -0
- python_platform/errors/lifecycle.py +164 -0
- python_platform/errors/modularity.py +100 -0
- python_platform/errors/services.py +100 -0
- python_platform/events/__init__.py +25 -0
- python_platform/events/aggregate.py +39 -0
- python_platform/events/catalog.py +136 -0
- python_platform/events/contracts.py +39 -0
- python_platform/events/contribution.py +128 -0
- python_platform/events/discovery.py +105 -0
- python_platform/events/errors.py +48 -0
- python_platform/events/runtime.py +192 -0
- python_platform/fastapi/__init__.py +49 -0
- python_platform/fastapi/action.py +175 -0
- python_platform/fastapi/adapter.py +381 -0
- python_platform/fastapi/application_services.py +647 -0
- python_platform/fastapi/background.py +42 -0
- python_platform/fastapi/contracts.py +278 -0
- python_platform/fastapi/errors.py +32 -0
- python_platform/fastapi/filters.py +111 -0
- python_platform/fastapi/health.py +44 -0
- python_platform/fastapi/http.py +55 -0
- python_platform/fastapi/http_router.py +212 -0
- python_platform/fastapi/manual_action.py +105 -0
- python_platform/fastapi/middleware.py +93 -0
- python_platform/fastapi/parameters.py +97 -0
- python_platform/fastapi/realtime/__init__.py +13 -0
- python_platform/fastapi/realtime/authentication.py +181 -0
- python_platform/fastapi/realtime/connection.py +166 -0
- python_platform/fastapi/realtime/module.py +41 -0
- python_platform/fastapi/realtime/options.py +50 -0
- python_platform/fastapi/realtime/runtime.py +423 -0
- python_platform/fastapi/request_context.py +244 -0
- python_platform/fastapi/route_integrity.py +88 -0
- python_platform/fastapi/routing.py +410 -0
- python_platform/fastapi/server.py +181 -0
- python_platform/fastapi/settings.py +40 -0
- python_platform/fastapi/tracing.py +62 -0
- python_platform/fastapi/transfer.py +128 -0
- python_platform/fastapi/upload_limits.py +63 -0
- python_platform/fastapi/uploads.py +94 -0
- python_platform/hosted_services/__init__.py +29 -0
- python_platform/hosted_services/bridge.py +420 -0
- python_platform/hosted_services/catalog.py +259 -0
- python_platform/hosted_services/contracts.py +55 -0
- python_platform/hosted_services/errors.py +53 -0
- python_platform/hosted_services/options.py +17 -0
- python_platform/hosted_services/runtime.py +267 -0
- python_platform/hosted_services/state.py +40 -0
- python_platform/hosting/__init__.py +4 -0
- python_platform/hosting/instance.py +40 -0
- python_platform/identity/__init__.py +73 -0
- python_platform/identity/application.py +287 -0
- python_platform/identity/contracts.py +283 -0
- python_platform/identity/errors.py +28 -0
- python_platform/identity/http_api.py +90 -0
- python_platform/identity/module.py +46 -0
- python_platform/identity/passwords.py +34 -0
- python_platform/identity/permissions.py +14 -0
- python_platform/identity/services.py +108 -0
- python_platform/identity/sqlalchemy/__init__.py +5 -0
- python_platform/identity/sqlalchemy/migrations/0001_platform_identity.py +151 -0
- python_platform/identity/sqlalchemy/migrations/0002_physical_delete.py +42 -0
- python_platform/identity/sqlalchemy/migrations/__init__.py +1 -0
- python_platform/identity/sqlalchemy/models.py +85 -0
- python_platform/identity/sqlalchemy/module.py +62 -0
- python_platform/identity/sqlalchemy/stores.py +526 -0
- python_platform/identity/tokens.py +106 -0
- python_platform/invocation/__init__.py +3 -0
- python_platform/invocation/callables.py +171 -0
- python_platform/invocation/contracts.py +33 -0
- python_platform/invocation/entries.py +54 -0
- python_platform/invocation/function_runtime.py +48 -0
- python_platform/invocation/interception.py +184 -0
- python_platform/lifecycle/__init__.py +25 -0
- python_platform/lifecycle/composition.py +35 -0
- python_platform/lifecycle/context.py +31 -0
- python_platform/lifecycle/runtime.py +43 -0
- python_platform/lifecycle/state.py +20 -0
- python_platform/modularity/__init__.py +15 -0
- python_platform/modularity/contracts.py +90 -0
- python_platform/modularity/discovery.py +143 -0
- python_platform/modularity/graph.py +334 -0
- python_platform/modularity/registry.py +100 -0
- python_platform/modularity/selection.py +16 -0
- python_platform/notifications/__init__.py +19 -0
- python_platform/notifications/catalog.py +46 -0
- python_platform/notifications/contracts.py +107 -0
- python_platform/observability/__init__.py +5 -0
- python_platform/observability/context.py +43 -0
- python_platform/observability/export.py +73 -0
- python_platform/observability/formatting.py +89 -0
- python_platform/observability/logging.py +118 -0
- python_platform/observability/options.py +45 -0
- python_platform/observability/tracing.py +80 -0
- python_platform/options/__init__.py +19 -0
- python_platform/options/aliases.py +331 -0
- python_platform/options/contribution.py +62 -0
- python_platform/options/immutability.py +48 -0
- python_platform/options/input_keys.py +214 -0
- python_platform/options/issues.py +335 -0
- python_platform/options/models.py +114 -0
- python_platform/options/registry.py +280 -0
- python_platform/options/schema.py +488 -0
- python_platform/options/validation.py +120 -0
- python_platform/py.typed +0 -0
- python_platform/realtime/__init__.py +12 -0
- python_platform/realtime/contracts.py +28 -0
- python_platform/realtime/diagnostics.py +37 -0
- python_platform/realtime/messages.py +113 -0
- python_platform/redis/__init__.py +6 -0
- python_platform/redis/distributed_lock.py +212 -0
- python_platform/redis/lease_lock.py +36 -0
- python_platform/redis/module.py +50 -0
- python_platform/redis/notification_runtime.py +182 -0
- python_platform/redis/notifications.py +25 -0
- python_platform/redis/options.py +35 -0
- python_platform/redis/runtime.py +116 -0
- python_platform/services/__init__.py +39 -0
- python_platform/services/application_bindings.py +221 -0
- python_platform/services/arbitration.py +381 -0
- python_platform/services/binding.py +102 -0
- python_platform/services/contribution.py +438 -0
- python_platform/services/convention.py +292 -0
- python_platform/services/convention_contracts.py +94 -0
- python_platform/services/exposure.py +23 -0
- python_platform/services/framework_provider.py +178 -0
- python_platform/services/native_graph.py +172 -0
- python_platform/services/provider.py +204 -0
- python_platform/services/registration.py +101 -0
- python_platform/services/runtime.py +298 -0
- python_platform/settings/__init__.py +30 -0
- python_platform/settings/application.py +95 -0
- python_platform/settings/binding.py +33 -0
- python_platform/settings/catalog.py +121 -0
- python_platform/settings/changes.py +14 -0
- python_platform/settings/contracts.py +115 -0
- python_platform/settings/definition_discovery.py +71 -0
- python_platform/settings/definitions.py +41 -0
- python_platform/settings/errors.py +22 -0
- python_platform/settings/handlers.py +43 -0
- python_platform/settings/management.py +57 -0
- python_platform/settings/manager.py +89 -0
- python_platform/settings/module.py +7 -0
- python_platform/settings/notifications.py +39 -0
- python_platform/settings/permissions.py +14 -0
- python_platform/settings/provider.py +74 -0
- python_platform/settings/refresh.py +140 -0
- python_platform/settings/refresh_module.py +45 -0
- python_platform/settings/sqlalchemy/__init__.py +5 -0
- python_platform/settings/sqlalchemy/migrations/0001_platform_settings.py +31 -0
- python_platform/settings/sqlalchemy/migrations/0002_physical_delete.py +32 -0
- python_platform/settings/sqlalchemy/migrations/0003_version_tokens.py +39 -0
- python_platform/settings/sqlalchemy/migrations/__init__.py +1 -0
- python_platform/settings/sqlalchemy/models.py +36 -0
- python_platform/settings/sqlalchemy/module.py +36 -0
- python_platform/settings/sqlalchemy/store.py +86 -0
- python_platform/settings/store.py +16 -0
- python_platform/settings/values.py +39 -0
- python_platform/sqlalchemy/__init__.py +51 -0
- python_platform/sqlalchemy/alembic_runtime/__init__.py +1 -0
- python_platform/sqlalchemy/alembic_runtime/env.py +27 -0
- python_platform/sqlalchemy/alembic_runtime/script.py.mako +14 -0
- python_platform/sqlalchemy/auditing.py +48 -0
- python_platform/sqlalchemy/errors.py +85 -0
- python_platform/sqlalchemy/metadata.py +538 -0
- python_platform/sqlalchemy/migration.py +346 -0
- python_platform/sqlalchemy/module.py +48 -0
- python_platform/sqlalchemy/module_migration.py +148 -0
- python_platform/sqlalchemy/options.py +66 -0
- python_platform/sqlalchemy/repository.py +33 -0
- python_platform/sqlalchemy/runtime.py +85 -0
- python_platform/sqlalchemy/session_provider.py +45 -0
- python_platform/sqlalchemy/unit_of_work.py +97 -0
- python_platform/testing/__init__.py +5 -0
- python_platform/testing/runtime.py +112 -0
- python_platform/unit_of_work/__init__.py +14 -0
- python_platform/unit_of_work/contracts.py +223 -0
- python_platform/unit_of_work/errors.py +27 -0
- python_platform/unit_of_work/manager.py +210 -0
- python_platform/unit_of_work/options.py +92 -0
- python_platform-0.1.1.dist-info/METADATA +122 -0
- python_platform-0.1.1.dist-info/RECORD +344 -0
- python_platform-0.1.1.dist-info/WHEEL +4 -0
- python_platform-0.1.1.dist-info/entry_points.txt +9 -0
- python_platform-0.1.1.dist-info/licenses/LICENSE +7 -0
- python_platform-0.1.1.dist-info/licenses/src/python_platform/background_jobs/pgqueuer/UPSTREAM_LICENSE.txt +21 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
"""一次 Application build 的 native Provider contribution ownership。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
from dishka import BaseScope, Provider, Scope
|
|
10
|
+
|
|
11
|
+
from ..application_services.catalog import ApplicationServiceMethod
|
|
12
|
+
from ..application_services.errors import ApplicationServiceDefinitionError
|
|
13
|
+
from ..application_services.interceptors import (
|
|
14
|
+
InterceptionStage,
|
|
15
|
+
Interceptor,
|
|
16
|
+
InterceptorRegistration,
|
|
17
|
+
_InterceptorRule,
|
|
18
|
+
)
|
|
19
|
+
from ..diagnostics import LifecycleStage, SourceLocation
|
|
20
|
+
from ..diagnostics.source import caller_source
|
|
21
|
+
from ..errors import RegistrationConflictError, ServiceContributorClosedError
|
|
22
|
+
from ..modularity import ModuleDescriptor, ModuleKey
|
|
23
|
+
from .binding import _collection_provider, _registration_providers
|
|
24
|
+
from .provider import _NativeProviderInspector, _ProviderSignature
|
|
25
|
+
from .registration import ProviderContribution, ProviderContributionView, RegistrationKind
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class _ContributionEntry:
|
|
30
|
+
entry_id: int
|
|
31
|
+
contribution: ProviderContribution
|
|
32
|
+
signature: _ProviderSignature
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ServiceContributor:
|
|
36
|
+
"""限定到一次 Module hook 的 native Provider contribution sink。"""
|
|
37
|
+
|
|
38
|
+
__slots__ = ("_active", "_descriptor", "_registry", "_stage")
|
|
39
|
+
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
*,
|
|
43
|
+
registry: ServiceContributionRegistry,
|
|
44
|
+
descriptor: ModuleDescriptor,
|
|
45
|
+
stage: LifecycleStage,
|
|
46
|
+
) -> None:
|
|
47
|
+
self._registry = registry
|
|
48
|
+
self._descriptor = descriptor
|
|
49
|
+
self._stage = stage
|
|
50
|
+
self._active = True
|
|
51
|
+
|
|
52
|
+
def contribute(
|
|
53
|
+
self,
|
|
54
|
+
provider: Provider,
|
|
55
|
+
*,
|
|
56
|
+
kind: RegistrationKind = RegistrationKind.EXPLICIT,
|
|
57
|
+
reason: str,
|
|
58
|
+
) -> None:
|
|
59
|
+
if not self._active:
|
|
60
|
+
raise ServiceContributorClosedError(stage=self._stage.value)
|
|
61
|
+
self._registry.add_from_hook(
|
|
62
|
+
provider=provider,
|
|
63
|
+
descriptor=self._descriptor,
|
|
64
|
+
stage=self._stage,
|
|
65
|
+
kind=kind,
|
|
66
|
+
reason=reason,
|
|
67
|
+
source=caller_source(str(self._descriptor.key), depth=2),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
def add_singleton(
|
|
71
|
+
self,
|
|
72
|
+
service: type[object],
|
|
73
|
+
implementation: type[object] | None = None,
|
|
74
|
+
*,
|
|
75
|
+
component: str = "",
|
|
76
|
+
multi: bool = False,
|
|
77
|
+
default: bool = False,
|
|
78
|
+
override: bool = False,
|
|
79
|
+
reason: str | None = None,
|
|
80
|
+
) -> None:
|
|
81
|
+
self._register(
|
|
82
|
+
service,
|
|
83
|
+
implementation,
|
|
84
|
+
scope=Scope.APP,
|
|
85
|
+
cache=True,
|
|
86
|
+
component=component,
|
|
87
|
+
multi=multi,
|
|
88
|
+
default=default,
|
|
89
|
+
override=override,
|
|
90
|
+
reason=reason,
|
|
91
|
+
source=caller_source(str(self._descriptor.key), depth=2),
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def add_scoped(
|
|
95
|
+
self,
|
|
96
|
+
service: type[object],
|
|
97
|
+
implementation: type[object] | None = None,
|
|
98
|
+
*,
|
|
99
|
+
scope: BaseScope = Scope.REQUEST,
|
|
100
|
+
component: str = "",
|
|
101
|
+
multi: bool = False,
|
|
102
|
+
default: bool = False,
|
|
103
|
+
override: bool = False,
|
|
104
|
+
reason: str | None = None,
|
|
105
|
+
) -> None:
|
|
106
|
+
self._register(
|
|
107
|
+
service,
|
|
108
|
+
implementation,
|
|
109
|
+
scope=scope,
|
|
110
|
+
cache=True,
|
|
111
|
+
component=component,
|
|
112
|
+
multi=multi,
|
|
113
|
+
default=default,
|
|
114
|
+
override=override,
|
|
115
|
+
reason=reason,
|
|
116
|
+
source=caller_source(str(self._descriptor.key), depth=2),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
def add_transient(
|
|
120
|
+
self,
|
|
121
|
+
service: type[object],
|
|
122
|
+
implementation: type[object] | None = None,
|
|
123
|
+
*,
|
|
124
|
+
scope: BaseScope = Scope.REQUEST,
|
|
125
|
+
component: str = "",
|
|
126
|
+
multi: bool = False,
|
|
127
|
+
default: bool = False,
|
|
128
|
+
override: bool = False,
|
|
129
|
+
reason: str | None = None,
|
|
130
|
+
) -> None:
|
|
131
|
+
self._register(
|
|
132
|
+
service,
|
|
133
|
+
implementation,
|
|
134
|
+
scope=scope,
|
|
135
|
+
cache=False,
|
|
136
|
+
component=component,
|
|
137
|
+
multi=multi,
|
|
138
|
+
default=default,
|
|
139
|
+
override=override,
|
|
140
|
+
reason=reason,
|
|
141
|
+
source=caller_source(str(self._descriptor.key), depth=2),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
def _register(
|
|
145
|
+
self,
|
|
146
|
+
service: type[object],
|
|
147
|
+
implementation: type[object] | None,
|
|
148
|
+
*,
|
|
149
|
+
scope: BaseScope,
|
|
150
|
+
cache: bool,
|
|
151
|
+
component: str,
|
|
152
|
+
multi: bool,
|
|
153
|
+
default: bool,
|
|
154
|
+
override: bool,
|
|
155
|
+
reason: str | None,
|
|
156
|
+
source: SourceLocation,
|
|
157
|
+
) -> None:
|
|
158
|
+
if not self._active:
|
|
159
|
+
raise ServiceContributorClosedError(stage=self._stage.value)
|
|
160
|
+
if override and (reason is None or not reason.strip()):
|
|
161
|
+
raise RegistrationConflictError(
|
|
162
|
+
key=None, sources=(source,), reason="explicit override requires a non-empty reason"
|
|
163
|
+
)
|
|
164
|
+
self._registry.add_registration(
|
|
165
|
+
service,
|
|
166
|
+
implementation,
|
|
167
|
+
descriptor=self._descriptor,
|
|
168
|
+
stage=self._stage,
|
|
169
|
+
scope=scope,
|
|
170
|
+
cache=cache,
|
|
171
|
+
component=component,
|
|
172
|
+
multi=multi,
|
|
173
|
+
default=default,
|
|
174
|
+
override=override,
|
|
175
|
+
reason=reason or f"service declared by {source.symbol}",
|
|
176
|
+
source=source,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def contributions(self) -> tuple[ProviderContributionView, ...]:
|
|
181
|
+
return self._registry.snapshot()
|
|
182
|
+
|
|
183
|
+
def _close(self) -> None:
|
|
184
|
+
self._active = False
|
|
185
|
+
|
|
186
|
+
def add_interceptor(
|
|
187
|
+
self,
|
|
188
|
+
interceptor: type[Interceptor],
|
|
189
|
+
*,
|
|
190
|
+
match: Callable[[ApplicationServiceMethod], bool],
|
|
191
|
+
before: InterceptionStage = InterceptionStage.METHOD,
|
|
192
|
+
) -> None:
|
|
193
|
+
"""只贡献匹配事实;类型及依赖仍通过原生 services 注册。"""
|
|
194
|
+
if not self._active:
|
|
195
|
+
raise ServiceContributorClosedError(stage=self._stage.value)
|
|
196
|
+
if (
|
|
197
|
+
not isinstance(interceptor, type)
|
|
198
|
+
or not issubclass(interceptor, Interceptor)
|
|
199
|
+
or inspect.isabstract(interceptor)
|
|
200
|
+
or not inspect.iscoroutinefunction(interceptor.intercept)
|
|
201
|
+
):
|
|
202
|
+
raise ApplicationServiceDefinitionError(
|
|
203
|
+
symbol=str(interceptor), reason="interceptor must implement async intercept"
|
|
204
|
+
)
|
|
205
|
+
if (
|
|
206
|
+
not callable(match)
|
|
207
|
+
or inspect.iscoroutinefunction(match)
|
|
208
|
+
or not isinstance(before, InterceptionStage)
|
|
209
|
+
):
|
|
210
|
+
raise ApplicationServiceDefinitionError(
|
|
211
|
+
symbol=interceptor.__qualname__,
|
|
212
|
+
reason="interceptor requires a synchronous match and valid position",
|
|
213
|
+
)
|
|
214
|
+
self._registry.add_interceptor_rule(
|
|
215
|
+
_InterceptorRule(
|
|
216
|
+
InterceptorRegistration(
|
|
217
|
+
interceptor,
|
|
218
|
+
before,
|
|
219
|
+
self._descriptor.key,
|
|
220
|
+
caller_source(str(self._descriptor.key), depth=2),
|
|
221
|
+
),
|
|
222
|
+
match,
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
class ServiceContributionRegistry:
|
|
228
|
+
"""一次 build 的 append-only collector;freeze 后只由仲裁流程读取。"""
|
|
229
|
+
|
|
230
|
+
__slots__ = ("_collections", "_declaration_counts", "_entries", "_frozen", "_interceptor_rules")
|
|
231
|
+
|
|
232
|
+
def __init__(self) -> None:
|
|
233
|
+
self._entries: list[_ContributionEntry] = []
|
|
234
|
+
self._declaration_counts: dict[ModuleKey, int] = {}
|
|
235
|
+
self._frozen = False
|
|
236
|
+
self._collections: set[type[object]] = set()
|
|
237
|
+
self._interceptor_rules: list[_InterceptorRule] = []
|
|
238
|
+
|
|
239
|
+
def add_interceptor_rule(self, rule: _InterceptorRule) -> None:
|
|
240
|
+
if self._frozen:
|
|
241
|
+
raise ServiceContributorClosedError(stage="interceptor")
|
|
242
|
+
self._interceptor_rules.append(rule)
|
|
243
|
+
|
|
244
|
+
@property
|
|
245
|
+
def interceptor_rules(self) -> tuple[_InterceptorRule, ...]:
|
|
246
|
+
return tuple(self._interceptor_rules)
|
|
247
|
+
|
|
248
|
+
def add_registration(
|
|
249
|
+
self,
|
|
250
|
+
service: type[object],
|
|
251
|
+
implementation: type[object] | None,
|
|
252
|
+
*,
|
|
253
|
+
descriptor: ModuleDescriptor,
|
|
254
|
+
stage: LifecycleStage,
|
|
255
|
+
scope: BaseScope,
|
|
256
|
+
cache: bool,
|
|
257
|
+
component: str,
|
|
258
|
+
multi: bool,
|
|
259
|
+
default: bool,
|
|
260
|
+
override: bool,
|
|
261
|
+
reason: str,
|
|
262
|
+
source: SourceLocation,
|
|
263
|
+
) -> None:
|
|
264
|
+
providers = _registration_providers(
|
|
265
|
+
service,
|
|
266
|
+
implementation,
|
|
267
|
+
scope=scope,
|
|
268
|
+
cache=cache,
|
|
269
|
+
component=component,
|
|
270
|
+
multi=multi,
|
|
271
|
+
default=default,
|
|
272
|
+
override=override,
|
|
273
|
+
identity=f"{descriptor.key}.{self._declaration_counts.get(descriptor.key, 0)}",
|
|
274
|
+
source=source,
|
|
275
|
+
)
|
|
276
|
+
if multi and service not in self._collections:
|
|
277
|
+
providers += ((_collection_provider(service), RegistrationKind.MULTI),)
|
|
278
|
+
self._collections.add(service)
|
|
279
|
+
for provider, kind in providers:
|
|
280
|
+
self.add_from_hook(
|
|
281
|
+
provider=provider,
|
|
282
|
+
descriptor=descriptor,
|
|
283
|
+
stage=stage,
|
|
284
|
+
kind=kind,
|
|
285
|
+
reason=reason,
|
|
286
|
+
source=source,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
def contributor(
|
|
290
|
+
self,
|
|
291
|
+
*,
|
|
292
|
+
descriptor: ModuleDescriptor,
|
|
293
|
+
stage: LifecycleStage,
|
|
294
|
+
) -> ServiceContributor:
|
|
295
|
+
return ServiceContributor(registry=self, descriptor=descriptor, stage=stage)
|
|
296
|
+
|
|
297
|
+
def add_from_hook(
|
|
298
|
+
self,
|
|
299
|
+
*,
|
|
300
|
+
provider: Provider,
|
|
301
|
+
descriptor: ModuleDescriptor,
|
|
302
|
+
stage: LifecycleStage,
|
|
303
|
+
kind: RegistrationKind,
|
|
304
|
+
reason: str,
|
|
305
|
+
source: SourceLocation,
|
|
306
|
+
) -> None:
|
|
307
|
+
if self._frozen:
|
|
308
|
+
raise ServiceContributorClosedError(stage=stage.value)
|
|
309
|
+
if not isinstance(provider, Provider):
|
|
310
|
+
raise RegistrationConflictError(
|
|
311
|
+
key=None,
|
|
312
|
+
sources=(source,),
|
|
313
|
+
reason="service contribution must be a native dishka.Provider",
|
|
314
|
+
)
|
|
315
|
+
if not isinstance(kind, RegistrationKind):
|
|
316
|
+
raise RegistrationConflictError(
|
|
317
|
+
key=None,
|
|
318
|
+
sources=(source,),
|
|
319
|
+
reason="registration kind must be RegistrationKind",
|
|
320
|
+
)
|
|
321
|
+
self._validate_hook_kind(kind=kind, stage=stage, source=source)
|
|
322
|
+
if not isinstance(reason, str) or not (normalized_reason := reason.strip()):
|
|
323
|
+
raise RegistrationConflictError(
|
|
324
|
+
key=None,
|
|
325
|
+
sources=(source,),
|
|
326
|
+
reason="service contribution reason must be a non-empty string",
|
|
327
|
+
)
|
|
328
|
+
validated = _NativeProviderInspector(source=source, kind=kind).inspect(provider)
|
|
329
|
+
self._append(
|
|
330
|
+
provider=provider,
|
|
331
|
+
owner=descriptor.key,
|
|
332
|
+
kind=kind,
|
|
333
|
+
source=source,
|
|
334
|
+
reason=normalized_reason,
|
|
335
|
+
signature=validated.signature,
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
def add_convention(
|
|
339
|
+
self,
|
|
340
|
+
*,
|
|
341
|
+
provider: Provider,
|
|
342
|
+
owner: ModuleKey,
|
|
343
|
+
source: SourceLocation,
|
|
344
|
+
reason: str,
|
|
345
|
+
) -> None:
|
|
346
|
+
kind = RegistrationKind.CONVENTION
|
|
347
|
+
validated = _NativeProviderInspector(source=source, kind=kind).inspect(provider)
|
|
348
|
+
self._append(
|
|
349
|
+
provider=provider,
|
|
350
|
+
owner=owner,
|
|
351
|
+
kind=kind,
|
|
352
|
+
source=source,
|
|
353
|
+
reason=reason,
|
|
354
|
+
signature=validated.signature,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
def _add_framework_default(
|
|
358
|
+
self,
|
|
359
|
+
*,
|
|
360
|
+
provider: Provider,
|
|
361
|
+
owner: ModuleKey,
|
|
362
|
+
source: SourceLocation,
|
|
363
|
+
reason: str,
|
|
364
|
+
) -> None:
|
|
365
|
+
"""框架 capability 的默认 binding 仍进入同一 native 仲裁与 drift guard。"""
|
|
366
|
+
|
|
367
|
+
if self._frozen:
|
|
368
|
+
raise ServiceContributorClosedError(stage="framework-default")
|
|
369
|
+
kind = RegistrationKind.DEFAULT
|
|
370
|
+
validated = _NativeProviderInspector(source=source, kind=kind).inspect(provider)
|
|
371
|
+
self._append(
|
|
372
|
+
provider=provider,
|
|
373
|
+
owner=owner,
|
|
374
|
+
kind=kind,
|
|
375
|
+
source=source,
|
|
376
|
+
reason=reason,
|
|
377
|
+
signature=validated.signature,
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
def freeze(self) -> tuple[_ContributionEntry, ...]:
|
|
381
|
+
self._frozen = True
|
|
382
|
+
return tuple(self._entries)
|
|
383
|
+
|
|
384
|
+
def snapshot(self) -> tuple[ProviderContributionView, ...]:
|
|
385
|
+
return tuple(
|
|
386
|
+
ProviderContributionView(
|
|
387
|
+
owner=entry.contribution.owner,
|
|
388
|
+
kind=entry.contribution.kind,
|
|
389
|
+
source=entry.contribution.source,
|
|
390
|
+
reason=entry.contribution.reason,
|
|
391
|
+
declaration_index=entry.contribution.declaration_index,
|
|
392
|
+
)
|
|
393
|
+
for entry in self._entries
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
def _append(
|
|
397
|
+
self,
|
|
398
|
+
*,
|
|
399
|
+
provider: Provider,
|
|
400
|
+
owner: ModuleKey,
|
|
401
|
+
kind: RegistrationKind,
|
|
402
|
+
source: SourceLocation,
|
|
403
|
+
reason: str,
|
|
404
|
+
signature: _ProviderSignature,
|
|
405
|
+
) -> None:
|
|
406
|
+
declaration_index = self._declaration_counts.get(owner, 0)
|
|
407
|
+
self._declaration_counts[owner] = declaration_index + 1
|
|
408
|
+
contribution = ProviderContribution(
|
|
409
|
+
provider=provider,
|
|
410
|
+
owner=owner,
|
|
411
|
+
kind=kind,
|
|
412
|
+
source=source,
|
|
413
|
+
reason=reason,
|
|
414
|
+
declaration_index=declaration_index,
|
|
415
|
+
)
|
|
416
|
+
self._entries.append(_ContributionEntry(len(self._entries), contribution, signature))
|
|
417
|
+
|
|
418
|
+
@staticmethod
|
|
419
|
+
def _validate_hook_kind(
|
|
420
|
+
*,
|
|
421
|
+
kind: RegistrationKind,
|
|
422
|
+
stage: LifecycleStage,
|
|
423
|
+
source: SourceLocation,
|
|
424
|
+
) -> None:
|
|
425
|
+
configure_kinds = (
|
|
426
|
+
RegistrationKind.DEFAULT,
|
|
427
|
+
RegistrationKind.EXPLICIT,
|
|
428
|
+
RegistrationKind.MULTI,
|
|
429
|
+
)
|
|
430
|
+
if stage is LifecycleStage.CONFIGURE and kind in configure_kinds:
|
|
431
|
+
return
|
|
432
|
+
if stage is LifecycleStage.POST_CONFIGURE and kind is RegistrationKind.OVERRIDE:
|
|
433
|
+
return
|
|
434
|
+
raise RegistrationConflictError(
|
|
435
|
+
key=None,
|
|
436
|
+
sources=(source,),
|
|
437
|
+
reason=f"registration kind {kind.value} is not allowed during {stage.value}",
|
|
438
|
+
)
|