Register Providers in the Container
masterTo use decorated classes, they must be registered with the container using container.register(). You can use several provider types to define how a token is resolved:
- Class Provider: Resolves a token using a class constructor (
useClass). - Value Provider: Resolves a token to a specific, pre-existing value (
useValue). - Factory Provider: Resolves a token using a factory function (
useFactory) that has access to theDependencyContainer. - Token Provider: Acts as an alias, redirecting one token to another (
useToken).
container.register<Foo>(Foo, {useClass: Foo});
container.register<Bar>(Bar, {useValue: new Bar()});
container.register<Baz>("MyBaz", {useValue: new Baz()});