text: Title: Bug: Extending middlewares or dependencies in the main application does not actually register them.
  Body: ### Description
  
  When I try to register middlewares or dependencies or even error_handlers from outside the main application, by extending them after creation rather than passing them directly, they appear to be in scope but are not actually present (or at least not recognized by Swagger, which requires them as path parameters).
  
  Interestingly, this issue does not occur with the Router, which is paradoxical.
  
  So, what i did wrong?
  
  ### URL to code causing the issue
  
  https://github.com/litestar-org/litestar/blob/main/litestar/app.py
  
  ### MCVE
  
  ```python
  def init_app(settings: Settings, *routers: Router) -> Litestar:
      log.info("Initialize Application")
  
      app = Litestar(
          [],
          path="/api",
          cors_config=CORSConfig(
              allow_origins=settings.server.origins,
              allow_methods=cast(list[Method | Literal["*"]], settings.server.methods),
              allow_headers=settings.server.headers,
              allow_credentials=True,
          ),
          csrf_config=(
              CSRFConfig(secret=settings.server.csrf_secret)
              if settings.server.csrf_secret
              else None
          ),
          openapi_config=(
              OpenAPIConfig(
                  title=settings.server.title,
                  version=settings.server.version,
                  servers=[Server(url=settings.server.domain)],
              )
              if settings.server.title
              else None
          ),
          debug=bool(settings.server.debug),
          middleware=get_current_common_middlewares(),
          exception_handlers=get_current_common_exception_handlers(),
          dependencies=deepcopy(proxy_app.dependencies),
          state=State(proxy_app.state),
          lifespan=[release_resources],
      )
  
      for router in routers:
          app.register(router)
      
      setup_dependencies(proxy_app, settings)
  
      return app
  
  
  ```
  ```py
  def setup_dependencies(app: Litestar, settings: Settings) -> None:
      log.info("Setup dependencies")
      engine = create_sa_engine(
          settings.db.url,
          pool_size=settings.db.connection_pool_size,
          max_overflow=settings.db.connection_max_overflow,
          pool_pre_ping=settings.db.connection_pool_pre_ping,
      )
      app.state.engine = engine
      conn_factory = create_sa_connection_factory(engine)
      manager_factory = create_db_manager_factory(conn_factory)
      hasher = get_argon2_hasher()
  
      mediator = CommandMediator()
      setup_command_mediator(
          mediator=mediator,
          manager=manager_factory,
          hasher=hasher,
      )
  
      app.dependencies["mediator"] = Provide(
          singleton(mediator), use_cache=True, sync_to_thread=False
      )
  ```
  
  And there how i fix it
  
  ```py
  
  def init_app(settings: Settings, *routers: Router) -> Litestar:
      log.info("Initialize Application")
      # NOTE It's frustrating to discover that extending or overriding the object to register dependencies or middlewares
      # does not actually register anything. What a mess!
      proxy_app = Litestar()
      setup_dependencies(proxy_app, settings)
  
      app = Litestar(
          [],
          path="/api",
          cors_config=CORSConfig(
              allow_origins=settings.server.origins,
              allow_methods=cast(list[Method | Literal["*"]], settings.server.methods),
              allow_headers=settings.server.headers,
              allow_credentials=True,
          ),
          csrf_config=(
              CSRFConfig(secret=settings.server.csrf_secret)
              if settings.server.csrf_secret
              else None
          ),
          openapi_config=(
              OpenAPIConfig(
                  title=settings.server.title,
                  version=settings.server.version,
                  servers=[Server(url=settings.server.domain)],
              )
              if settings.server.title
              else None
          ),
          debug=bool(settings.server.debug),
          middleware=get_current_common_middlewares(),
          exception_handlers=get_current_common_exception_handlers(),
          dependencies=deepcopy(proxy_app.dependencies),
          state=State(proxy_app.state),
          lifespan=[release_resources],
      )
  
      del proxy_app
  
      for router in routers:
          app.register(router)
  
      return app
  ```
  
  
  ### Steps to reproduce
  
  _No response_
  
  ### Screenshots
  
  _No response_
  
  ### Logs
  
  _No response_
  
  ### Litestar Version
  
  2.9.1
  
  ### Platform
  
  - [ ] Linux
  - [X] Mac
  - [ ] Windows
  - [ ] Other (Please specify in the description above)