Cannot register ProductCalculator because it is a Singleton #658
Replies: 4 comments
-
|
Please provide more information of what is actually not possible in the singleton? HttpContextAccessor should be injectable in a singleton so it’s unclear in your steps to replicate what actually fails. |
Beta Was this translation helpful? Give feedback.
-
|
You're right, sorry. It's MemberManager that is not injectable. I need it to get a user from a I have managed to fix it currently using IServiceScopeFactory, so it's not the end of the world, but it would be nice to be able to inject it normally. |
Beta Was this translation helpful? Give feedback.
-
|
I had the exact same issue today with PriceAdjuster, where I had to calculate a discount based on members. I solved it as @ToxicKevinFerm by using IServiceScopeFactory like this But yea, being able to do regular DI would be preferable. |
Beta Was this translation helpful? Give feedback.
-
|
I guess we could make the calculators transient as they shouldn't be storing any state, but I'd imagine this would be classed as a breaking change so I'll need to review a) if this has any side effects and b) when would make sense to change this. I appreciate the feedback 👍 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I cannot register a custom ProductCalculator because it is a Singleton. I need to access HttpContext and Umbraco services outside of examine because my prices are decided by the currently logged in user.
Steps To Reproduce
Inject
IHttpContextAccessororMemberServicein yourProductCalculator.Expected behavior
I expect to be able to run ProductCalculator as scoped or at least not be locked to Singleton. When I use the built in
AddScopedinstead ofAddUniqueit doesn't pick up the service at all.Umbraco Commerce version:
13.0.0
Beta Was this translation helpful? Give feedback.
All reactions