如何将应用程序用作依赖项两次

How can I use the application twice as dependency

Elixir/Erlang application 可能有依赖的应用程序。根据文档:

you can configure the generated application by defining an application/0 function in your mix.exs with the following options:

• :applications - all applications your application depends on at
  runtime. By default, this list is automatically inferred from your
  dependencies. Any extra Erlang/Elixir dependency must be specified in
  :extra_applications. Mix and other tools use the application list in order
  to start your dependencies before starting the application itself.
• :extra_applications - a list of Erlang/Elixir applications that you
  want started before your application. For example, Elixir's :logger or
  Erlang's :crypto.

这些依赖的应用程序将在启动我的应用程序之前全部启动。到目前为止一切顺利。

applications 键需要一个原子列表,它不允许元组。这使得无法将参数传递给 Application.start/2.

是否有任何可靠的方法将 start_args 传递给相关应用程序,或者我是否被迫使用手动 MyApp.start(:normal, [:hello]) 调整默认行为?

如果答案是“是”,我怎样才能使用不同的 start_args 列表启动同一个依赖应用程序 两次

简短的回答是否定的。 Elixir 不会对所有同一个应用程序进行多次启动。但是,您可以使用一些技巧。

在 deps 中添加 app: false,应用程序将不会自动启动。

{:my_dep, "...", app: false}

然后您可以从您的主应用程序启动它。

MyDep.Application.start(...)

然后您可以尽早在您的主要主管中启动应用程序中的其他工作人员。

您在应用中需要注意的一些事项。

  • 应用程序是否使用命名进程?那将是一个问题。
  • 应用程序是否有全局配置?这可能是个问题。

但是所有这些实际上都取决于您尝试使用的依赖项。