Application Configuration

Configuration is done using a context class, which defines various methods which can be overridden. The recommended way of defining an application context is by inheriting from either ProductionJivagoContext or DebugJivagoContext, and overriding specific methods.

from typing import List

from jivago.config.production_jivago_context import ProductionJivagoContext
from jivago.config.router.router_builder import RouterBuilder
from jivago.event.event_bus import EventBus
from jivago.jivago_application import JivagoApplication
from jivago.lang.registry import Registry

class MyApplicationContext(ProductionJivagoContext):

    def __init__(self, root_package: "Module", registry: Registry, banner: bool = True):
        super().__init__(root_package, registry, banner)

    def configure_service_locator(self):

    def scopes(self) -> List[type]:
        return super().scopes()

    def get_views_folder_path(self) -> str:
        return super().get_views_folder_path()

    def get_config_file_locations(self) -> List[str]:
        return super().get_config_file_locations()

    def create_router_config(self) -> RouterBuilder:
        return super().create_router_config()

    def get_default_filters(self):
        return super().get_default_filters()

    def create_event_bus(self) -> EventBus:
        return super().create_event_bus()

    def get_banner(self) -> List[str]:
        return super().get_banner()

app = JivagoApplication(my_package, context=MyApplicationContext)

Configuration methods

This method can be used to manually bind classes to the internal ServiceLocator. See Dependency Injection for more details.
This method defines component scopes for the ServiceLocator which determine when to instantiate new components. By default, only the Singleton exists.
This method defines the folder in which template files are stored for RenderedView responses. Defaults to the views submodule of the root package.
Defines a list of files which should be tried when importing the application properties. The ApplicationProperties is creating using the first existent file in this rule. Defaults to ["application.yml", "application.json", "properties.yml", "properties.json"].
This method is used to configure the Router object which is used to resolve requests. See Router Configuration for details.
Used only on subclasses of ProductionJivagoFilter. This method is called from create_router_config to define the default FilteringRule.
Used to register event handlers.
Defines the ASCII-art banner which is printed in the console at every startup.

ApplicationProperties and SystemEnvironmentProperties

Both the ApplicationProperties and SystemEnvironmentProperties dictionaries can be injected into a component class, thus providing access namely to the contents of the application config file, and to the environment variables. For instance, for an application.yml file placed in the working directory, an appropriate ApplicationProperties object is created.


my_property: "foobar"

from import ApplicationProperties
from jivago.inject.annotation import Component
from jivago.lang.annotations import Inject

class MyComponent(object):

    def __init__(self, application_properties: ApplicationProperties):
        self.application_properties = application_properties

    def do_something(self):