Base solution for your next web application
Open Closed

Where should I call a subscribe for a general notification #928


User avatar
0
hole7 created

Hi,

I'd like to subscribe to a general notification like 'NewUserCreated'

I know that firstly I (admin user) must subscribe to that notification. Then, when there is a new user created, I will receive a notification.

I can figure how to publish a notification in this case ( call Publish notification CreateUser function of UserService, for example)

But, I'm confusing where should I put the code for subscribe to that Notification?

Anyone please help me!

I saw from the document:

public class MyService : ITransientDependency { private readonly INotificationSubscriptionManager _notificationSubscriptionManager;

public MyService(INotificationSubscriptionManager notificationSubscriptionManager)
{
    _notificationSubscriptionManager = notificationSubscriptionManager;
}

//Subscribe to a general notification
public async Task Subscribe_SentFrendshipRequest(int? tenantId, long userId)
{
    await _notificationSubscriptionManager.SubscribeAsync(tenantId, userId, "SentFrendshipRequest");    
}

//Subscribe to an entity notification
public async Task Subscribe_CommentPhoto(int? tenantId, long userId, Guid photoId)
{
    await _notificationSubscriptionManager.SubscribeAsync(tenantId, userId, "CommentPhoto", new EntityIdentifier(typeof(Photo), photoId));   
}

}

But with my case I don't think of any service that will appropriate for a general subscription like that. And when should I call the Subscribe_SentFriendshipRequest, for example?

Thank you


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    For example, you can create a page for users to allow to subscribe notifications. In that page, if use choice to get notification when a new user is inserted, then you can subscribe current user to that notification. This is exactly what we did for AspNet Zero product.

  • User Avatar
    0
    hole7 created

    Hi hikalkan,

    I got it.

    Thank you very much :)

  • User Avatar
    0
    jackwang created

    <cite>hikalkan: </cite> For example, you can create a page for users to allow to subscribe notifications.

    In some cases, we assume a user has some default subscriptions, where should I start the initialization of these subscriptions. On the registration in Account/Register controller or UserAppService or UserMangeer? What it the best practice.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If both registered users and the users created from app by admin or any other user will be registered to these notifications, it is better to do it in usermanager I think.