Hello World
The runnable example uses plain constructor injection and a controller action
registered through the Route facade. The application owns service providers;
the separate HTTP kernel discovers routes/api.py.
Start the example from the framework repository:
uv sync --locked --all-groups
uv run uvicorn --app-dir examples/hello-world app:app --reload
Open http://127.0.0.1:8000/welcome. The controller returns:
{"message":"Hello, Titancore"}
Define a service and provider¶
The example's greeting_service.py defines GreetingService. Its provider
registers one application-scoped instance:
from greeting_service import GreetingService
from titancore.container import Provider, Scope, provide
class ExampleServiceProvider(Provider):
@provide(scope=Scope.APP)
def provide_greeting(self) -> GreetingService:
return GreetingService()
Define a controller action¶
In welcome_controller.py, use a plain service annotation:
from greeting_service import GreetingService
class WelcomeController:
def __init__(self, service: GreetingService) -> None:
self._service = service
def show(self) -> dict[str, str]:
return {"message": self._service.message()}
The kernel resolves the controller and its constructor dependencies for the request. No endpoint injection decorator is needed for this constructor.
Declare the route¶
In routes/api.py, name the controller and action directly:
from welcome_controller import WelcomeController
from titancore.facades import Route
Route.get("/welcome", (WelcomeController, "show"))
Compose the application¶
The example's app.py supplies its root and registers the provider before
creating the kernel:
from pathlib import Path
from service_provider import ExampleServiceProvider
from titancore import Application
from titancore.foundation.http import Kernel
application = Application(Path(__file__).resolve().parent)
application.register(ExampleServiceProvider())
kernel = Kernel(application)
app = kernel.asgi
The same routes/api.py file also exposes / through a function action.
Plain service annotations use the existing request resolver:
from greeting_service import GreetingService
from titancore.facades import Route
from titancore.foundation.http import inject
@inject
async def welcome(service: GreetingService) -> dict[str, str]:
return {"message": service.message()}
Route.get("/", welcome)
FastAPI retains parsing for query values and Pydantic request bodies. Native HTTP context parameters also retain their host behavior. Opaque service classes resolve through the application container. Explicit annotation metadata retains its existing meaning.
For the conventional application directory structure, environment configuration, readiness route, and tests, see the official application skeleton.