jeudi 23 novembre 2017

ASP .NET MVC & SignalR push notifications clean architecture

I'm working on a live notification system using ASP .NET MVC with SignalR.

My app has three layers like this:

enter image description here

All my app methods are already built and working and I'm currently adding a notification system using SignalR.

The problem I'm facing is that I need to modify every method that might imply a notification sending to return an array of users to be notified, an array that might be empty (because notifications might be turned off for that operation).

SignalR hub is installed in the MVC layer so I can't call it from my Business Logic Layer (BAL). I know I can solve it in a clean way with SQL Dependencies, but that's not an option.

An example would be (pseudocode):

Controler.cs (Without notifications)

    AddComent(Comment){
      int error = BALComments.AddComment(Comment);
      return View();   
    }

Controler.cs (With notificacions)

    AddComent(Comment){
      NotificationHub notifHub;
      int error = BALComments.AddComment(Comment,UserArray);
      notifHub(UserArray);
      return View();   
    }

The question is how to modify every "notificable" method in my business logic layer without explicitly change every method to return an optional user array list.

1 commentaire: