-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[FEATURE REQ] Azure Service Bus Enforce mandatory processor arguments on CreateProcessor #19101
Comments
Track 2 had this as an overload. When supplied, it would be called. Otherwise, the exception would bubble up. While it was not a trivial signature it did reveal the intent. A mandatory error handler should be required at construction time if the processor has to have it. |
Hi @danielmarbach, |
The reasons we prefer events (in this case) are:
BTW, whether something is a Func delegate or event does not change how many handlers can be chained, i.e. using System;
class Program
{
static void Main()
{
Func<bool> handler = () => { return true; };
handler += () => { return false; }; // last delegate wins, i.e. handler() == false
var processor = new Processor(handler);
}
}
class Processor
{
public Processor(Func<bool> handler) { }
} |
Fair enough. This is my personal feedback from my fiddling around with the new API. That certainly doesn't invalidate all the previous user studies. Mine is just an opinion I wanted to share. Happy to close after seeing the explanation. My mind was kind of caught up in finding a solution that would lead me to use it the proper way without having to be told with a runtime exception |
@KrzysztofCwalina correct chaining is possible. Although the syntax you showed here is not exactly the canonical way how I've seen developers adding multiple event handlers. Most of the time I've seen people doing thing.Event ±= Handler1; |
Thanks for sharing the background info. Learned a ton. |
I agree that chaining delegates is not something that people do. Many don't even know that it's possible. But in real world, not many people chain event handlers either. So, in the end, the issue of chaining multiple handlers/delegates is a red herring IMO. The real tradeoff is compile enforcement vs runtime enforcement of the requirement to have two handlers. I think compile time enforcement is better when the error/exception (caused by API misuse) is likely to not happen in testing. Runtime enforcement is better if the exception is going to happen in testing. In the case of the processor, no processing will run unless both handlers are provided (~100% chance of exception when testing). |
Right now I can do the following
but if I try to start this I get a runtime exception telling me
given that only ever one handler can be assigned, which is enforced by
azure-sdk-for-net/sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/ServiceBusProcessor.cs
Line 289 in 6e4c8ea
why not enforce the two required handler parameters as input to
CreateProcessor
? How useful is it that those two are exposed as "event handler delegate" that are not really event handler delegates (because normally you could have multiple, here you can't) and in all the cases you always have to set both?I think a similar API to the following would be more intention revealing and avoid runtime errors:
Once you have that signature it becomes clear for me as a user of the API that I always have to specify both. Then it might also become an option to rename the parameter from
*EventArgs
so something different because really those handlers are not real multicast .NET events.The text was updated successfully, but these errors were encountered: