Redth / PushSharp

A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, Windows 8, Amazon, Blackberry, and (soon) FirefoxOS devices!
Other
4.38k stars 1.52k forks source link

PushBroker refactoring adds a static type constraint on the notification #270

Closed ghost closed 8 years ago

ghost commented 11 years ago

The ServiceRegistration support on the last version of PushBroker makes the method GetRegistrations (and QueueNotification) generic. Because of that, polymorphic QueueNotification(notif) calls with notif being of superclass Notification type are no longer possible.

The solution to this is to remove all genericity and use a type like before, this way:

    public void QueueNotification(Notification notification)
    {
        var services = GetRegistrations(notification.GetType());
        foreach (var s in services)
            s.QueueNotification(notification);
    }

et caetera. All these methods would have a paramater Type type instead of a type parameter TPushNotification, or the latter adds a compiling-time constraint to the notification queueing.

Redth commented 10 years ago

Can you give me a snippet of code for the scenario that's now broken for you?

ghost commented 10 years ago

My code is too heavy and I'm not really allowed to share it.

But here is the scenario I brought to you on JabbR :

« I have a broker set up for several different services. Then I loop over a List and queue them
« problem, they're then only known as "Notification" so the GetRegistrations generic method finds no candidate service to send queue them to « for instance you can have a list of two notifs : [BlackberryNotification, AndroidNotification], then you loop with foreach(var notif in list) « I can't call QueueNotification<typeof(notif)>(notif) at runtime

« but I CAN call QueueNotification(notif) with no generics, which will call GetRegistrations(typeof(notif))

« instead of GetRegistrations()

So basicallythe generic methods prevent you from doing polymorphic calls. It used to work when they weren't generic (and they're not on my modified version of PushSharp, it's mostly a simple revert change.

I hope I'm clear enough, thank you once more for your time.

Greetings from France, hope everything's alright in Canada

:)

Le Jeudi 28 novembre 2013 21h19, Jon Dick notifications@github.com a écrit :

Can you give me a snippet of code for the scenario that's now broken for you? — Reply to this email directly or view it on GitHub.