# `MishkaCmsCore.ProviderRegistry`
[🔗](https://github.com/mishka-group/mishka_cms_core/blob/v0.0.1/lib/mishka_cms_core/provider_registry.ex#L5)

Providers as `mishka_installer` plugins — the half `MishkaCmsCore.Mail.Provider` and
`MishkaCmsCore.Captcha.Provider` share.

A provider is a module that listens on its kind's event and adds itself to the `providers` list
the event carries. `use` makes a module that plugin:

    use MishkaCmsCore.ProviderRegistry, event: "mail:providers", priority: 10

`all/2`, `offered/2` and `fetch/3` ask the event which providers are installed: every registered
module that implements the kind's behaviour, the first of each id. Stopping a provider's plugin in
the installer takes it out of the list. Nothing is cached: the event is asked each time.

An event whose plugins cannot run — one of them is not loaded, so `Hook.call/3` answers its
`cannot_run:` option — cannot say which providers are installed: `all/2` and `offered/2` list
none, and `fetch/3` answers `{:error, :cannot_run}` rather than `{:error, :unknown_provider}`.

# `all`

```elixir
@spec all(String.t(), module()) :: [module()]
```

Every provider registered on `event` that implements `behaviour`, the first of each id.

# `fetch`

```elixir
@spec fetch(String.t(), module(), String.t() | nil) ::
  {:ok, module()} | {:error, :unknown_provider | :cannot_run}
```

The offered provider registered on `event` under `id`; `{:error, :cannot_run}` when the event's
plugins cannot run, so whether it is installed cannot be told.

# `offered`

```elixir
@spec offered(String.t(), module()) :: [module()]
```

The providers of `all/2` this installation offers: every one, unless its `offered?/0` says not.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
