Dotnetnuke 在DNN 7中初始化NotificationController

Dotnetnuke 在DNN 7中初始化NotificationController,dotnetnuke,dotnetnuke-6,dotnetnuke-7,Dotnetnuke,Dotnetnuke 6,Dotnetnuke 7,如何在DNN 7.1.2中初始化通知控制器 我试过: var nc = new DotNetNuke.Services.Social.Notifications.NotificationController(); 但是这是空的,没有可调用的方法。。。我是不是初始化错了 当然,除了ToString、GetType、Equals和GetHashCode 我需要能够创建通知类型和创建通知 谢谢您可以使用通知controller.Instance.SendNotification方法发送通知。 以下是

如何在DNN 7.1.2中初始化通知控制器

我试过:

var nc = new DotNetNuke.Services.Social.Notifications.NotificationController();
但是这是空的,没有可调用的方法。。。我是不是初始化错了

当然,除了
ToString
GetType
Equals
GetHashCode

我需要能够创建通知类型和创建通知


谢谢

您可以使用
通知controller.Instance.SendNotification
方法发送通知。 以下是一个例子:

var notificationType = NotificationsController.Instance.GetNotificationType("HtmlNotification");
var portalSettings = PortalController.GetCurrentPortalSettings();
var sender = UserController.GetUserById(portalSettings.PortalId, portalSettings.AdministratorId);

var notification = new Notification {NotificationTypeID = notificationType.NotificationTypeId, Subject = subject, Body = body, IncludeDismissAction = true, SenderUserID = sender.UserID};
NotificationsController.Instance.SendNotification(notification, portalSettings.PortalId, null, new List<UserInfo> { user });
var notificationType=notificationscocontroller.Instance.GetNotificationType(“HtmlNotification”);
var portalSettings=PortalController.GetCurrentPortalSettings();
var sender=UserController.GetUserById(portalSettings.PortalId、portalSettings.AdministratorId);
var notification=new notification{NotificationTypeID=notificationType.NotificationTypeID,Subject=Subject,Body=Body,IncludeDismissAction=true,SenderUserID=sender.UserID};
NotificationsController.Instance.SendNotification(通知,portalSettings.PortalId,null,新列表{user});

这将向特定用户发送通知。

如果您需要创建自己的通知类型,请使用下面的代码作为指导,它将创建一个通知类型“GroupApprovedNotification”。这是来自核心组模块

type = new NotificationType { Name = "GroupApprovedNotification", Description = "Group Approved Notification", DesktopModuleId = deskModuleId };
if (NotificationsController.Instance.GetNotificationType(type.Name) == null)
{
    NotificationsController.Instance.CreateNotificationType(type);

}

NotificationsController
使用DNN的(有点奇怪)
ServiceLocator
模式,它只是一个静态容器,当您调用静态
实例
方法时,它会为您提供一个接口实例。它主要用于支持可测试性;如果要在测试中获得备用实例,可以调用static
setStableInstance
方法。在整个DNN中,有许多类型遵循此模式(许多不遵循此模式的旧控制器都有一个对应的
Testable*控制器)。