开发者

Alternative to global events

I am developing a FOSS service bus.

One of the things developers will need is to hook into certain events that take place. Currently I have a static ServiceBusEvents class that exposes all of the possible events that may be of interest, e.g.:

public static event BeforeEnqueueMessageDelegate BeforeEnqueueMessage = delegate { };
public static event BeforeDequeueMessageDelegate BeforeDequeueMessage = delegate { };
public static event AfterEnqueueMessageDelegate AfterEnqueueMessage = delegate { };
public static event AfterDequeueMessageDelegate AfterDequeueMessage = delegate { };

There are a finite 开发者_如何转开发number of events but I don't know whether this is the best way to go.

Is there a 'cleaner' way to get the same thing done?


Just have 1 event and make the first parameter the eventname. That will make your library future proof, as a new event wont alter the existing interface. The disadvantage is that any parameter would need to be casted before it could be used. (Alternatively, use a base class for the event and people can switch on the type of that instead)


OK, so there doesn't appear to any strong objection to this or there is no real 'cleaner' way :)

Thanks for your input Cine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜