Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 1022 Bytes

container.md

File metadata and controls

36 lines (28 loc) · 1022 Bytes

Container

:container is a simple extension that allows you to configure a dependency injection container to be accessible from a WebPipe::Conn instance.

The container to use must be configured under the :container config key. It will be accessible through the #container method.

Although you'll usually want to configure the container in the application class (for instance, using dry-system), having it at the connection struct level is useful for building other extensions that may need to access to it, like the hanami_view one.

require 'web_pipe'
require 'my_container'

WebPipe.load_extensions(:container)

class MyApp
  plug :config, WebPipe::Plugs::Config.(
    container: MyContainer
  )
  plug :this, :this # Resolved thanks to the container in `include`
  plug :that
  
  private
  
  def that(conn)
    conn.set_response_body(
      conn.container['do'].() # Resolved thanks to the container in `:config`
    )
  end
end