Container resolve does work anymore with default parameters since v4.4
See original GitHub issueDescribe the bug DI does not work properly when using default values.
Error: Cannot inject the dependency at position #0 of "Target" constructor. Reason:
TypeInfo not known for "Object"
To Reproduce Build and run main.
import "reflect-metadata";
import {container, injectable} from "tsyringe";
@injectable()
class Target {
constructor(subject = "hello world") {}
}
function main() {
const t = container.resolve(Target);
}
Expected behavior t correctly resolved with t.subject == “hello world”
Version: tsyringe v4.4
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:18
Top Results From Across the Web
Registration Concepts — Autofac 6.0.0 documentation
You register components with Autofac by creating a ContainerBuilder and informing the builder which components expose which services. Components can be ...
Read more >"Least Astonishment" and the Mutable Default Argument
When Python encounters it, the first thing it will do is compile it in order to create a code object for this function....
Read more >Troubleshoot issues when using Azure Functions trigger for ...
Common issues, workarounds, and diagnostic steps, when using the Azure Functions trigger for Azure Cosmos DB.
Read more >Change log - PHP-DI
#343 Autowiring and Annotations do not work for object() inside arrays: it ... #223: DI\ContainerInterface was deprecated since v4.1 and has been removed....
Read more >Docker Desktop release notes - Docker Documentation
Fixed container DNS lookups when using Registry Access Management. For Mac. Fixed an issue preventing the Analyze Image button on the Images tab...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That is your solution using Tsyring but if you need to create runtime Config instances I don’t recommend you use singleton or Tsyringe, use a simple class.
Why is it closed but it’s not the best approach?
This is how I solved the problem indeed this solution is in the part of documentation…
https://github.com/microsoft/tsyringe#injecting-primitive-values-named-injection
But I don’t think this is the best approach because you are forced to make an extern initialization… Hopefully, the dev team will implement the logical behaviour and we won’t need to use that.