Base solution for your next web application
Open Closed

AbpNotificationSubscriptions table #12531


User avatar
0
Loizos created

Version 13.4.0, Angular 18, .NET 8

Hi support,

Is there an easy way to query AbpNotificationSubscriptions table? I was trying to find the AbpNotificationSubscriptions entity class so that to inject with IRepository but couldn't find it.

Unfortunately the INotificationSubscriptionManager is not the case as there is not any function that returns what we want.

Thanks, Loizos

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

2 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @Loizos

    The AbpNotificationSubscriptions table is not exposed via a standard IRepository, so you cannot directly inject a repository for it. Instead, the ABP framework provides services to work with notification definitions and subscriptions.

    If you need to access notification subscription data, you should use the following:

    • INotificationDefinitionManager lets you query available notification definitions. For example, you can check if a notification is defined, list definitions, etc.

    • INotificationStore gives you direct access to subscription and notification entities (including NotificationSubscriptionInfo). You can use methods like:

      • GetSubscriptionsAsync(...)
      • InsertUserNotificationAsync(...)
      • IsSubscribedAsync(...)

    Example usage:

    public class MyNotificationAppService : ApplicationService
    {
        private readonly INotificationStore _notificationStore;
        private readonly INotificationDefinitionManager _notificationDefinitionManager;
    
        public MyNotificationAppService(
            INotificationStore notificationStore,
            INotificationDefinitionManager notificationDefinitionManager)
        {
            _notificationStore = notificationStore;
            _notificationDefinitionManager = notificationDefinitionManager;
        }
    
        public async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptions(long userId)
        {
            return await _notificationStore.GetSubscriptionsAsync(new UserIdentifier
                {
                    TenantId = AbpSession.TenantId,
                    UserId = userId
                }
            );
        }
    }
    

    This way you don’t need to query the table directly the framework provides abstractions for it.

    If you specifically need raw access to the subscription records, you can still fall back to DbContext.Set<NotificationSubscriptionInfo>(), but the recommended approach is to use INotificationStore since it encapsulates the logic for working with the AbpNotificationSubscriptions table.

    Related Source Code (INotificationStore)

    Related Source Code (INotificationDefinitionManager)

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    Loizos created

    Hi @oguzhanagir

    Thank you for your fast response on this!

    Yes I was looking for NotificationSubscriptionInfo so that to inject it in my class and be able to query the table directly so thanks for all the information, I found what I wanted within your suggested source code (NotificationStore class).

    Basically both INotificationStore and INotificationDefinitionManager do not work for me as I cannot get back a list of all entity type subscriptions because the EntityId is included in predicate, so I just needed to build custom query.

    Issue solved thanks for help again!

    Regards, Loizos

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)