DI tokenization was broken, well, more hacked than broken for Tsyringe. It was a long time coming, but we needed a way that we can resolve tokenized items from the registry without dual singleton creation when wanting to get the same item from the container.
I originally created a method to get items and filter them each time. this imposed multiple issues:
it's slow
it caused ALL discordx dependancies to be resolved every time they where asked
it broke lazy loading
In order to solve this issue, i created an Instance Cashing Singleton Factory that, when an item from a token is resolved, would register the same token via the singleton factory and return that same item back to the container, effectivally registerting the class in BOTH the symbol and the constructor as a token.
This speeds up the resolution using symbols as tokens and allows us to effectivally manage, produce and resolve multiple types of tokens under the same cross-cutting concern. you don't need to encaplusate the same module anymore as the container will create 2 tokens for the same object.
Breaking changes
If you are using tokenization in Tsyringe using the previous filter method, then you might want to revert back to the standard method of injection
What about TypeDI?
I dunno lol
Package
@discordx/di
This has been tested by running the examples on my own test bot.
DI tokenization was broken, well, more hacked than broken for Tsyringe. It was a long time coming, but we needed a way that we can resolve tokenized items from the registry without dual singleton creation when wanting to get the same item from the container.
I originally created a method to get items and filter them each time. this imposed multiple issues:
In order to solve this issue, i created an
Instance Cashing Singleton Factory
that, when an item from a token is resolved, would register the same token via the singleton factory and return that same item back to the container, effectivally registerting the class in BOTH the symbol and the constructor as a token.This speeds up the resolution using symbols as tokens and allows us to effectivally manage, produce and resolve multiple types of tokens under the same cross-cutting concern. you don't need to encaplusate the same module anymore as the container will create 2 tokens for the same object.
Breaking changes
If you are using tokenization in Tsyringe using the previous filter method, then you might want to revert back to the standard method of injection
What about TypeDI?
I dunno lol
Package
This has been tested by running the examples on my own test bot.