<commit_before># Effective Angular: Dependency Injection

> **NOTE**: This is a work-in-progress, and not yet final. Some of the links may
> be substituted with `(...)`, and some TODOs or missing parts may be in the
> documentation.

There are many different ways to use AngularDart to provide and utilize
dependency injection throughout your application, components, and services. This
guide is meant to serve as a **development tool** and to help push **best
practices** from the developers of the AngularDart framework.

*   [Providers](#providers)
    *   [DO use the "named" providers](#do-use-the-named-providers)
    *   [DO use factories for
        configuration](#do-use-factories-for-configuration)
    *   [DO use `const` providers](#do-use-const-providers)
    *   [DO use the `.forToken` constructor for
        tokens](#do-use-the-fortoken-constructor-for-tokens)
    *   [PREFER `ClassProvider` to a `Type`](#...)
*   [Tokens](#tokens)
    *   [DO use typed `OpaqueToken<T>`](#do-use-typed-opaquetokent)
    *   [AVOID using arbitrary tokens](#avoid-using-arbitrary-tokens)
    *   [PREFER `MultiToken<T>` to `multi: true`](#...)
*   [Injectors](#injectors)
    *   [AVOID using `ReflectiveInjector`](#avoid-using-reflectiveinjector)
*   [Components](#components)
    *   [AVOID using injection to configure individual components](#...)
*   [Annotations](#annotations)
    *   [PREFER omitting `@Injectable()` where possible](#...)

## Providers

### DO use the "named" providers

While not formally deprecated, `provide(...)` and `Provider(...)` require
certain combinations of named optional parameters, and allow combinations that
otherwise will not compile or perform as intended. For example:

**BAD**:

```dart
// This is valid with the older syntax. What does it mean?
const Provider(
  Foo,<commit_msg>Adds missing links in table of contents<commit_after># Effective Angular: Dependency Injection

> **NOTE**: This is a work-in-progress, and not yet final. Some of the links may
> be substituted with `(...)`, and some TODOs or missing parts may be in the
> documentation.

There are many different ways to use AngularDart to provide and utilize
dependency injection throughout your application, components, and services. This
guide is meant to serve as a **development tool** and to help push **best
practices** from the developers of the AngularDart framework.

*   [Providers](#providers)
    *   [DO use the "named" providers](#do-use-the-named-providers)
    *   [DO use factories for
        configuration](#do-use-factories-for-configuration)
    *   [DO use `const` providers](#do-use-const-providers)
    *   [DO use the `.forToken` constructor for
        tokens](#do-use-the-fortoken-constructor-for-tokens)
    *   [PREFER `ClassProvider` to a `Type`](#prefer-classprovider-to-a-type)
*   [Tokens](#tokens)
    *   [DO use typed `OpaqueToken<T>`](#do-use-typed-opaquetokent)
    *   [AVOID using arbitrary tokens](#avoid-using-arbitrary-tokens)
    *   [PREFER `MultiToken<T>` to `multi:
        true`](#prefer-multitokent-to-multi-true)
*   [Injectors](#injectors)
    *   [AVOID using `ReflectiveInjector`](#avoid-using-reflectiveinjector)
*   [Components](#components)
    *   [AVOID using injection to configure individual
        components](#avoid-using-injection-to-configure-individual-components)
*   [Annotations](#annotations)
    *   [PREFER omitting `@Injectable()` where
        possible](#prefer-omitting-injectable-where-possible)

## Providers

### DO use the "named" providers

While not formally deprecated, `provide(...)` and `Provider(...)` require
certain combinations of named optional parameters, and allow combinations that
otherwise will not compile or perform as intended. For example:

**BAD**:

```dart
// This is valid with the older syntax. What does it mean?
const Provider(
  Foo,
{'fraction_non_alphanumeric': 0.12574694725902832, 'fraction_numerical': 0.0, 'mean_word_length': 4.006501950585175, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2598133', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1098, 'n_words': 375}