Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion py_spring_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from py_spring_core.event.commons import ApplicationEvent
from py_spring_core.event.application_event_handler_registry import EventListener

__version__ = "0.0.15"
__version__ = "0.0.16"

__all__ = [
"PySpringApplication",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_origin,
)

from fastapi import FastAPI
from loguru import logger
from pydantic import BaseModel

Expand Down Expand Up @@ -57,7 +58,8 @@ class ApplicationContext:
The `ApplicationContext` class is designed to follow the Singleton design pattern, ensuring that there is a single instance of the application context throughout the application's lifetime.
"""

def __init__(self, config: ApplicationContextConfig) -> None:
def __init__(self, config: ApplicationContextConfig, server: FastAPI) -> None:
self.server = server
self.all_file_paths: set[str] = set()
self.primitive_types = (bool, str, int, float, type(None))

Expand Down
3 changes: 2 additions & 1 deletion py_spring_core/core/application/py_spring_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ def __init__(
self.app_context_config = ApplicationContextConfig(
properties_path=self.app_config.properties_file_path
)
self.app_context = ApplicationContext(config=self.app_context_config)
self.fastapi = FastAPI()
self.app_context = ApplicationContext(config=self.app_context_config, server=self.fastapi)


self.classes_with_handlers: dict[
Type[AppEntities], Callable[[Type[Any]], None]
Expand Down
9 changes: 7 additions & 2 deletions tests/test_application_context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from fastapi import FastAPI
import pytest

from py_spring_core.core.application.context.application_context import (
Expand All @@ -12,9 +13,13 @@

class TestApplicationContext:
@pytest.fixture
def app_context(self):
def server(self) -> FastAPI:
return FastAPI()

@pytest.fixture
def app_context(self, server: FastAPI):
config = ApplicationContextConfig(properties_path="")
return ApplicationContext(config)
return ApplicationContext(config, server=server)

def test_register_entities_correctly(self, app_context: ApplicationContext):
class TestComponent(Component): ...
Expand Down
9 changes: 7 additions & 2 deletions tests/test_component_features.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABC
from typing import Annotated

from fastapi import FastAPI
import pytest

from py_spring_core.core.application.context.application_context import (
Expand All @@ -14,10 +15,14 @@ class TestComponentFeatures:
"""Test suite for component features including primary components, qualifiers, and registration validation."""

@pytest.fixture
def app_context(self):
def server(self) -> FastAPI:
return FastAPI()

@pytest.fixture
def app_context(self, server: FastAPI):
"""Fixture that provides a fresh ApplicationContext instance for each test."""
config = ApplicationContextConfig(properties_path="")
return ApplicationContext(config)
return ApplicationContext(config, server=server)

def test_qualifier_based_injection(self, app_context: ApplicationContext):
"""
Expand Down
9 changes: 7 additions & 2 deletions tests/test_entity_provider.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from fastapi import FastAPI
import pytest

from py_spring_core.core.application.context.application_context import (
Expand All @@ -18,12 +19,16 @@ class TestEntityProvider:
@pytest.fixture
def test_entity_provider(self):
return EntityProvider(depends_on=[TestComponent])

@pytest.fixture
def server(self) -> FastAPI:
return FastAPI()

@pytest.fixture
def test_app_context(
self, test_entity_provider: EntityProvider
self, test_entity_provider: EntityProvider, server: FastAPI
) -> ApplicationContext:
app_context = ApplicationContext(ApplicationContextConfig(properties_path=""))
app_context = ApplicationContext(ApplicationContextConfig(properties_path=""), server=server)
app_context.providers.append(test_entity_provider)
return app_context

Expand Down