Migrating to dynamic supervisor

I am trying to address this warning in my repo
warning: :simple_one_for_one strategy is deprecated, please use DynamicSupervisor instead

I have updated all deps as recommended by some online solutions.

I have tried to migrate to using DynamicSupervisor but 3 problems:

  1. i still see the warning
  2. this does not do what i was doing initially whereby My.ChildProcess is started when application starts
  3. instead of one supervisor now i had a supervisor that starts a dynamic supervisor that starts My.ChildProcess??? Why do i need to do this?
defmodule My.Application do
  use Application

  @impl true
  def start(_type, _args) do
    children = [
      {DynamicSupervisor, strategy: :one_for_one, name: My.DynamicSupervisor}

    Supervisor.start_link(children, strategy: :one_for_one)
defmodule My.DynamicSupervisor do
  use DynamicSupervisor

  def start_link(init_arg) do
    DynamicSupervisor.start_link(__MODULE__, init_arg, name: __MODULE__)

  def start_child() do
    spec = %{id: My.ChildProcess, start: {My.ChildProcess, :start_link, [[]]}}
    DynamicSupervisor.start_child(__MODULE__, spec)

  @impl true
  def init(init_arg) do
      strategy: :one_for_one,
      extra_arguments: [init_arg]

I don’t have the same setup… and naming your dynamic supervisor My.DynamicSupervisor is asking for trouble (when using aliases for example)

Not the same syntax in the application, i just use

children = [

Not the same child_spec, and I put it in the worker, not in supervisor. Example…

  def child_spec(args) do
      id: __MODULE__,
      start: {__MODULE__, :start_link, args},
      restart: :transient,
      type: :worker

and I start children like this

  def start_child(args \\ %{}) do
    DynamicSupervisor.start_child(__MODULE__, {Worker, [args]})

I am using Registry to name dynamic workers.

  1. Are You sure You don’t have a dependency using simple_one_for_one?
  2. Dynamic workers are meant to start on demand, why do You need to start it on boot?
  3. Supervisor may have different strategies, and supervision tree is a tree that can be deep, with multiple levels of supervisors.

You should show your worker.

Answering your questions below