-
Notifications
You must be signed in to change notification settings - Fork 10
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
Question: How to work with dependency overrides from factory method? #105
Comments
Hi there, unfortunately, there is no way to access the resolution request's In the meantime, could you explain your case a bit more? Is it a must to access the overrides? |
I plan to use dependency overrides to pass parameters into the constructor and need to make sure that the parameters instance(s) is/are passed as dependency override and are not created as transient dependency by Stashbox itself. |
I came up with an idea and pushed it into the pre-release channel, here you can check the test for the usage. What do you think? |
Thank you for the very good solution. During my tests, I ran info a new issue: It is not possible to tell the UnknownRegistrationConfigurator to not resolve an unknown type if the service type is a class type. In that case, the UnknownRegistrationConfigurator is already initialized correctly, so that I did not find a working solution with the current implementation, as I have added a method to
To make this work, a null check must be added to
Unfortunately, this also breaks dependency overrides as Stashbox does the dependency override check after it checks for registration validity. So, dependency overrides currently cannot be used to pass values into types that are not yet registered. |
So, you want to tell in the unknown type configurator to DO NOT resolve some types, right? Then, I would approach this in a different way. What do you think about this syntax: This list would be checked in the resolver to skip the containing types from resolution. Or just a general
|
Yes, but this makes it neccessary for me to process all types that I do not want to register, which might be thousands. At the moment, I do this check when StashBox tries to resolve an unknown type. I did not recognize yet that it will always resolve class types. I have updated the pull request #106 - renamed the Reset() method to Skip(), which simply resets the factory and implementation type of the context, and added a check for dependency overrides. |
Alright, after a second thought I also ended up with the second solution, it feels more granular for the context. I checked your PR and I rather introduce a new bool property where we store the info about skipping. Also, the dependency override check is not relevant at that point because the unknown type resolution is executed far after the override search. |
I added the dependency override check there because I ran into an That's why I am unhappy with my solution, as the whole resolving stuff is not neccessary for types that are already available as dependency override. |
That sounds weird, it shouldn't be picked by the unknown resolution when it's available as override. Let me check this out. Do you have a quick failing example? Thanks! |
Your solution with |
Coming back to the original question, also your test code works fine. But unfortunately, there is no Update - I have added the following methods to |
I merged your PR and made those methods available for decorators, also, gave them some tests. Could you please try the latest version? Thanks! |
Thank you, now everything works as expected. |
Changes are released in v3.6.4 |
I can use RegistrationConfigurator.WithFactory to register a factory method. That's fine. But now I need to check for specific dependency overrides in that factory method. If a class is not available in the dependency overrides, I want to handle this myself in the factory (by calculating a specific default value that might change from time to time).
Is that possible?
The text was updated successfully, but these errors were encountered: