Open fernandomoraesvr opened 7 months ago
Well, both of my issues are in auto_injector, but i'll keep this issue open and expect some answer before opening an issue in auto_injector repository.
I tried to change PositionalParam to not required in auto_injector and noticed that this will be propably not trivial. Yet, my main issue is regarding replaceInstance
Any updates on this? @fernandomoraesvr were you able to solve the replaceInstance
not working?
Describe the question So my company team is migrating from Modular v5 to Modular v6 and we faced two issues when migrating.
The first one is, PositionalParams is being instanced as required parameters, what is not true, is this a known limitation regarding runtime injection? If it is not, i would be pleasure to contribute and resolve this possible issue.
Example: Dio has BaseOptions PositionalParam, what makes the following code throw an exception:
i.addSingleton<Dio>(Dio.new);
That can be fixed by the following code:
i.addSingleton<Dio>(() => Dio(BaseOptions()));
Well, this behaviour is not the end of the world, but i guess it could be fixed by PositionalParam be instanced with isRequired = false (or not due to limitations).
The second issue is that
replaceInstance
in our case is not replacing any Bind inside other instances, example:RequestService contains Dio, which only gets replaced if i use replaceInstance in RequestService, this behavior occur in AnyRepository (it has RequestService instance, so i have to replace AnyRepository with ReplaceService that already is an instance with mocked Dio).
Expected behavior I did not known if both provided examples are expected or not, but i expect that replaceInstance replaces instances in cascade for any bind in Modular and define PositionalParam as not required.
Screenshots Since the code is from my company, i was not allowed to provide screenshots from our code, but i would be happy to help with more examples if needed.