def create_application(db_engine) -> Application:
    """Creates new instance of the application"""
    application = Application(
        "BiddingApp",
        app_version=0.1,
        db_engine=db_engine,
    )
    application.include_submodule(catalog_module)
    application.include_submodule(bidding_module)

    @application.on_create_transaction_context
    def on_create_transaction_context(**kwargs):
        engine = application.get_dependency("db_engine")
        session = Session(engine)
        correlation_id = uuid.uuid4()
        logger.correlation_id.set(uuid.uuid4())  # type: ignore

        # create IoC container for the transaction
        dependency_provider = ContainerProvider(
            TransactionContainer(
                db_session=session, correlation_id=correlation_id, logger=logger
            )
        )

        return TransactionContext(dependency_provider)

    @application.on_enter_transaction_context
    def on_enter_transaction_context(ctx: TransactionContext):
        ctx.set_dependencies(publish=ctx.publish)
        logger.debug("Entering transaction")

    @application.on_exit_transaction_context
    def on_exit_transaction_context(
        ctx: TransactionContext, exception: Optional[Exception] = None
    ):
        session = ctx["db_session"]
        if exception:
            session.rollback()
            logger.warning(f"rollback due to {exception}")

            # from pydantic import ValidationError
            # if type(exception) not in [ValidationError]:
            #     raise exception
        else:
            session.commit()
            logger.debug(f"committed")
        session.close()
        logger.debug(f"transaction ended")
        logger.correlation_id.set(uuid.UUID(int=0))  # type: ignore

    @application.transaction_middleware
    async def logging_middleware(ctx: TransactionContext, call_next):
        description = (
            f"{ctx.current_action[1]} -> {repr(ctx.current_action[0])}"
            if ctx.current_action
            else ""
        )
        logger.debug(f"Executing {description}...")
        result = call_next()
        if asyncio.iscoroutine(result):
            result = await result
        logger.debug(f"Finished executing {description}")
        return result

    @application.transaction_middleware
    async def event_collector_middleware(ctx: TransactionContext, call_next):
        handler_kwargs = call_next.keywords

        result = call_next()
        if asyncio.iscoroutine(result):
            result = await result

        logger.debug(f"Collecting event from {ctx['message'].__class__}")

        domain_events = []
        repositories = filter(
            lambda x: hasattr(x, "collect_events"), handler_kwargs.values()
        )
        for repo in repositories:
            domain_events.extend(repo.collect_events())
        for event in domain_events:
            logger.debug(f"Publishing {event}")
            await ctx.publish_async(event)

        return result

    return application
Creates new instance of the application
src/config/container.py