Quick Reference ("How Do I...")
Table of Contents
Getting Started
How do I inject a service into my component?
When should I use resolve() vs @inject?
resolve() vs @inject?Method
Use When
Benefits
How do I create a service?
Injecting Dependencies
How do I inject multiple services?
How do I make a dependency optional?
How do I inject all implementations of a service?
How do I lazy-load a service?
Creating Services
Which registration helper should I use?
Helper
What it does
Typical use
How do I create a simple service?
How do I inject dependencies into my service?
How do I create a service without auto-registration?
How do I use a class directly without an interface?
Service Lifetimes
What are the different service lifetimes?
Lifetime
Description
Use For
How do I create a singleton service?
How do I create a transient service?
How do I force a new instance regardless of registration?
Advanced Injection
How do I inject into properties (not constructor)?
How do I create a factory for my service?
How do I publish my own scoped context?
How do I scope a service to a component?
How do I inject the last registered instance?
How do I plug in custom factories or transformers?
Container Management
How do I configure a container?
How do I create a custom container?
How do I create a child container?
How do I register multiple implementations?
How do I register instances directly?
How do I check or override an existing registration?
How do I deregister a service?
Testing
How do I mock services for testing?
How do I test a service with dependencies?
Common Patterns
How do I create a configuration service?
How do I create a service with initialization logic?
How do I implement the Service Locator pattern?
How do I create a plugin system?
Troubleshooting
Error: "Cannot resolve key"
Error: "Cyclic dependency"
resolve() returns undefined
TypeScript errors with resolve()
resolve()Service isn't a singleton (getting different instances)
Constructor injection order mismatch
Complete Documentation
Last updated
Was this helpful?