Skip to content

Quick Start

santiago edited this page Jan 29, 2026 · 1 revision

Quick Start

Get started with azfunc-boot in just a few steps.

1. Create a Service Registry

A service registry is where you register all your application services. Create a class that inherits from BaseServiceRegistry:

from azfunc_boot import BaseServiceRegistry, DependencyContainer, register_service

class ServicesRegistry(BaseServiceRegistry):
    def __init__(self, container: DependencyContainer):
        self.container = container
        super().__init__()

    @register_service
    def register_services(self):
        # Simple registration
        self.container.add_scoped(ExampleService)
        
        # Registration with interface using lambda
        self.container.add_scoped(
            IExampleService,
            lambda: ExampleService(self.container.get_service(ExampleDisposableClient)),
        )

2. Create a Controller

Controllers organize your Azure Functions triggers. Create a class that inherits from BaseController:

import logging
from azfunc_boot import BaseController, DependencyContainer
import azure.functions as func

from services.example_service import ExampleService


class ExampleController(BaseController):
    PATH = "example"

    def __init__(self, container: DependencyContainer, bp: func.Blueprint):
        super().__init__(container, bp)
        self._logger = logging.getLogger(__name__)

    def register_routes(self):
        self.bp.route(self.PATH, methods=["GET"])(self.example_method)

    async def example_method(self, req: func.HttpRequest) -> func.HttpResponse:
        self._logger.info("Example method called")
        param = req.params.get("param")
        if not param:
            return func.HttpResponse("Param is required", status_code=400)

        service: ExampleService = self.container.get_service(ExampleService)
        try:
            result = await service.example_method(param)
            return func.HttpResponse(result, status_code=200)
        except Exception as e:
            self._logger.error(f"Error in example_method: {e}")
            return func.HttpResponse(f"Error: {e}", status_code=500)

3. Bootstrap Your Application

In your function_app.py, use create_app to initialize the framework:

import logging
import azure.functions as func
from azfunc_boot import create_app

logging.basicConfig(level=logging.INFO, force=True)

# Create the application using the framework
app, container = create_app(
    controllers_package="controllers", registries_package="registries"
)


@app.route("health_check", methods=["GET"], auth_level=func.AuthLevel.ANONYMOUS)
def health_check(req: func.HttpRequest) -> func.HttpResponse:
    """Health check endpoint"""
    return func.HttpResponse("Healthy", status_code=200)

That's it! The framework will automatically:

  • Discover and register all controllers in the controllers package
  • Discover and register all service registries in the registries package
  • Set up dependency injection
  • Manage scopes for your services

Next Steps

Clone this wiki locally