public static void AddToastNotify(this IServiceCollection services, ToastNotifyOptions options = null) { if (options == null) { options = new ToastNotifyOptions(); } if (services == null) { throw new ArgumentNullException(nameof(services)); } #region Framework Services //Check if a TempDataProvider is already registered. var tempDataProvider = services.FirstOrDefault(d => d.ServiceType == typeof(ITempDataProvider)); if (tempDataProvider == null) { //Add a tempdata provider when one is not already registered services.AddSingleton <ITempDataProvider, CookieTempDataProvider>(); } //check if IHttpContextAccessor implementation is not registered. Add one if not. var httpContextAccessor = services.FirstOrDefault(d => d.ServiceType == typeof(IHttpContextAccessor)); if (httpContextAccessor == null) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); } #endregion //Add TempDataWrapper for accessing and adding values to tempdata. services.AddSingleton <ITempDataService, TempDataService>(); services.AddSingleton <INotificationContainer <Notification>, NotificationContainer <Notification> >(); services.AddSingleton(options); //Add the ToastNotification implementation services.AddScoped <IToastNotifyService, ToastNotifyService>(); }
public ToastNotifyViewComponent(IToastNotifyService service, ToastNotifyOptions options) { this._service = service; _options = options; }