Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Modules
You can also use modules to organize your dependencies.
Loading modules
Modules can then be loaded in your container.
By default, when you create a container, it is using a default module under the hood.
The dependencies do not need to be registered in the same module as the one that is using them.
Note that the module name used as a key is a symbol.
Modules override
You can also override dependencies of a module. The dependencies of the module will be overridden by the dependencies of the last loaded module.
Unload modules
You can also unload a module from the container. The dependencies of the module will be removed from the container.
Already cached instances will be removed to keep consistency and avoid potential errors.
Using scopes
Singleton scope (default)
In singleton scope, the container returns the same instance every time a dependency is resolved.
Transient scope
In transient scope, the container returns a new instance every time the dependency is resolved.
Scoped Scope
In scoped scope, the container returns the same instance within a scope. Different scopes will have different instances.
To use the scoped scope, you need to create a scope using runInScope.
Note: If you try to resolve a scoped dependency outside a scope, an error will be thrown.