I think you have to inject the INotificationService interface in your ctor. In Umbraco 8 everything can be 'injected', so where v7 contains some hard binded things, in v8 things are more seperated, so I think you can inject the notifications service when you would like to use it.
Try something like this:
public class ContentServiceHelper
{
private readonly IContentService _contentService;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly INotificationService _notificationService;
public ContentServiceHelper(IContentService contentService, IUmbracoContextAccessor umbracoContextAccessor, INotificationService notificationService)
{
_contentService = contentService;
_umbracoContextAccessor = umbracoContextAccessor;
_notificationService = notificationService;
}
public IContent CreateContent(string name)
{
var content = _contentService.CreateContent(name, -1, DocType.ModelTypeAlias);
var result = _contentService.SaveAndPublish(content);
if (result.Success)
{
IUser user = null;
if (_umbracoContextAccessor.UmbracoContext != null)
{
user = _umbracoContextAccessor.UmbracoContext.Security.CurrentUser;
if (user != null)
{
_notificationService.SendNotifications(
user,
new[] { content },
"action",
"actionName",
new Uri("/"),
x => "subject",
x => "body"
}
}
}
return content;
}
}
I don't have tried this code sample yet, but it maybe gives you a headstart.
Also, have a look at the source code of Umbraco V8 at:
SaveAndPublishWithStatus(message)
" Services.ContentService.SaveAndPublishWithStatus(message); " Why this code is not working Umbraco8?
I believe this method is not available in V8
No Another solution?
I think you have to inject the
INotificationService
interface in yourctor
. In Umbraco 8 everything can be 'injected', so where v7 contains some hard binded things, in v8 things are more seperated, so I think you can inject the notifications service when you would like to use it.Try something like this:
I don't have tried this code sample yet, but it maybe gives you a headstart. Also, have a look at the source code of Umbraco V8 at:
https://github.com/umbraco/Umbraco-CMS/blob/61cc22dccf65e3e0077f5fb93c4e0aa447abe581/src/Umbraco.Web/Compose/NotificationsComponent.cs
is working on a reply...