-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from types import ModuleType | ||
|
||
|
||
@dataclass(frozen=True) | ||
class WireupSettings: | ||
"""Class containing Wireup settings specific to Django.""" | ||
|
||
service_modules: list[str | ModuleType] | ||
"""List of modules containing wireup service registrations.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
from __future__ import annotations | ||
|
||
import importlib | ||
from typing import TYPE_CHECKING | ||
|
||
from django.apps import AppConfig | ||
from django.conf import settings | ||
|
||
from wireup import container, warmup_container | ||
|
||
if TYPE_CHECKING: | ||
from wireup.integration.django import WireupSettings | ||
|
||
|
||
class WireupConfig(AppConfig): | ||
"""Integrate wireup with Django.""" | ||
|
||
name = "wireup.integration.django" | ||
|
||
def ready(self) -> None: # noqa: D102 | ||
service_modules = settings.WIREUP.get("SERVICE_MODULES", []) | ||
integration_settings: WireupSettings = settings.WIREUP | ||
|
||
for entry in dir(settings): | ||
if not entry.startswith("__") and hasattr(settings, entry): | ||
container.params.put(entry, getattr(settings, entry)) | ||
|
||
warmup_container(container, [importlib.import_module(m) if isinstance(m, str) else m for m in service_modules]) | ||
warmup_container( | ||
container, | ||
[importlib.import_module(m) if isinstance(m, str) else m for m in integration_settings.service_modules], | ||
) |