Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PositionalParam is required and replaceInstance in cascade #955

Open
fernandomoraesvr opened this issue Apr 12, 2024 · 2 comments
Open

PositionalParam is required and replaceInstance in cascade #955

fernandomoraesvr opened this issue Apr 12, 2024 · 2 comments
Labels
new New issue request attention question Questions about using some feature or general working of the package

Comments

@fernandomoraesvr
Copy link

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:

i.addSingleton<Dio>(() => Dio(BaseOptions()));
i.addSingleton<RequestService>(RequestService.new);
i.addSingleton<AnyRepository>(AnyRepository.new)

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.

@fernandomoraesvr fernandomoraesvr added new New issue request attention question Questions about using some feature or general working of the package labels Apr 12, 2024
@fernandomoraesvr
Copy link
Author

fernandomoraesvr commented Apr 12, 2024

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

@DjordjeMancic97
Copy link

Any updates on this? @fernandomoraesvr were you able to solve the replaceInstance not working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new New issue request attention question Questions about using some feature or general working of the package
Projects
None yet
Development

No branches or pull requests

2 participants