处理请求时发生未处理的异常

时间:2017-05-11 14:02:41

标签: c# asp.net-core identityserver4

  

InvalidOperationException:无法解析类型的服务   'IdentityServer.Core.Infrastructure.Notifications.INotificationsService'   在尝试激活时   'IdentityServer.Admin.Web.Controllers.HomeController'。

HomeController中:

public class HomeController : Controller
    {
        private readonly INotificationsService _notificationsService;
        private readonly ISettingsService _settingsService;

        public HomeController(INotificationsService notificationsService, ISettingsService settingsService)
        {
            _notificationsService = notificationsService;
            _settingsService = settingsService;
        }

        public ActionResult Index()
        {
            return RedirectToAction("Index", "Users");
        }

        public PartialViewResult Alerts()
        {
            return PartialView(new AlertsViewModel(_notificationsService.Active()));
        }
    }

我的创业公司:

public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        }

这是INotificationsService:

 public interface INotificationsService
  {
    void Add(NotificationItem item);
    void Remove(Guid id);
    void Cleanup();

    IEnumerable<NotificationItem> All { get; }
  }

  public static class NotificationsServiceExtensions
  {
    public static void Add(this INotificationsService parent, Guid id, NotificationType type, string title, 
      string message, IEnumerable<NotificationLink> links, DateTime expiration)
    {
      parent.Add(new NotificationItem(id, type, title, message, links, expiration));
    }

    public static void Add(this INotificationsService parent, NotificationType type, string title,
      string message, string linkTitle, string link)
    {
      parent.Add(new NotificationItem(Guid.NewGuid(), type, title, message, new List<NotificationLink>() { new NotificationLink(linkTitle, link)}, 
        DateTime.Now.AddSeconds(30)));
    }

    public static void Add(this INotificationsService parent, NotificationType type, string title, string message)
    {
      parent.Add(new NotificationItem(Guid.NewGuid(), type, title, message, new List<NotificationLink>(), DateTime.Now.AddSeconds(30)));
    }

    public static IEnumerable<NotificationItem> Active (this INotificationsService parent)
    {
      return parent.All.Where(x => x.Expiration > DateTime.Now);
    }
  }

我知道我想以某种方式将它添加到startup.cs,但我真的不明白这一点,我是MVC和ASP.NET Core的新手。

0 个答案:

没有答案