Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple Commanded apps #298

Merged
merged 18 commits into from
Sep 12, 2019
Merged

Support multiple Commanded apps #298

merged 18 commits into from
Sep 12, 2019

Conversation

slashdotdash
Copy link
Member

@slashdotdash slashdotdash commented Aug 1, 2019

Add support for defining one or more Commanded application modules for your Elixir app.

Each application is independent, isolated, and its lifecycle is controlled by you (started in your app's own supervision tree).

Examples

A basic application defines the otp_app (for its configuration) and includes one or more router modules.

defmodule MyApp.Application do
  use Commanded.Application, otp_app: :my_app

  router MyApp.Router
end

The above application could be configured with:

# config/config.exs
config :my_app, MyApp.Application,
  event_store: [
    adapter: Commanded.EventStore.Adapters.EventStore,
    event_store: MyApp.EventStore
  ],
  pub_sub: :local,
  registry: :local

Alternatively, you can include the event store, pubsub, and registry config when defining the application:

defmodule MyApp.Application do
  use Commanded.Application,
    otp_app: :my_app,
    event_store: [
      adapter: Commanded.EventStore.Adapters.EventStore,
      event_store: MyApp.EventStore
    ],
    pubsub: :local,
    registry: :local

  router(MyApp.Router)
end

Commands are dispatched using the Application:

:ok = MyApp.Application.dispatch(%ExampleCommand{})

For backwards compatibility commands can be dispatch using a router, but must specify the application as an option:

:ok = MyApp.Router.dispatch(%ExampleCommand{}, application: MyApp.Application)

Supervision

The Commanded application(s) you define must be started, typically by including them in your Elixir application's supervision tree:

defmodule MyApp do
  use Application

  def start(_type, _args) do
    children = [
      MyApp.Application
    ]

    Supervisor.start_link(children, strategy: :one_for_one)
  end
end

Fixes #117.

@xtagon
Copy link

xtagon commented Sep 13, 2019

Yay! Congrats on this one, it's a big one!

@andreapavoni
Copy link

Congrats! this is one of the key features I really needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multiple Commanded apps
3 participants