-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
MockJSRuntime: Consider using TryAddSingleton in AddMockJSRuntime() #207
Comments
Hey there! I wanted to pick up this issue but I'm a little confused by the level of detail so I hope you don't mind me rambling a bit: The |
Hey Mark, You raise a good point. To be honest, I didn't think of that before I added this issue, so this might not be a good idea after all. What's your take? I guess my idea was that if two competing helper methods both register a IJSRuntime, the built in one should throw if added. But users should really be aware of what they are doing at this level, so it might not be the right thing to do. Users might indeed want to override an existing registration. |
Yeah - it's a difficult one because you would hope that users should be aware of what they are doing if they get to these lower levels. You could remove the
This would also decouple you from the (I guess you could call it a) side effect of the di always injecting the last known class, meaning that if a consumer is brave enough to register their own they would have to know these things by looking at the documentaiton of the service provider that Microsoft owns. Alternatively you could leave it as is and rely on the fact that people doing this sort of lower level injection are aware of what they are doing. I think either way some notes on this sort of thing in the documentation would be great - so that consumers know the potential pitfalls that can happen here. Just as a side note, not really that relevant is the kind of funny thing of users doing something like |
LOL, didnt know. Anyway, I think this issue should be parked for now, and I will reopen it if turns out to be big problem. The point with If you want to work on something related to this, then this issue obvious: #115 Thanks for taking the time Mark! |
To avoid confusion when a
IJSRuntime
has already been registered with theTestServiceProvider
, lets useTryAddSingleton
instead and throw an exception if it or some other mock has already been registered.The text was updated successfully, but these errors were encountered: