public NotificationHubService( NotificationHubServiceOptions notificationHubServiceOptions, ILogger <NotificationHubService> logger, IJSRuntime jsRuntime) { _notificationApiInterop = new NotificationJsInterop(jsRuntime); _logger = logger; _hubConnection = new HubConnectionBuilder() .WithUrl(notificationHubServiceOptions.Uri, options => { options.AccessTokenProvider = notificationHubServiceOptions.AccessTokenProvider; }) .WithAutomaticReconnect() .Build(); _hubConnection.On <string, string, string>(nameof(INotificationHubService.ReceiveNotification), async(title, description, iconurl) => { await _notificationApiInterop.Notify(title, description, iconurl); }); _hubConnection.On(nameof(INotificationHubService.ReceivePermissionRequest), async() => { await _notificationApiInterop.AskForApproval(); }); }
public static void AddNotificationHub(this IServiceCollection serviceCollection, Action <IServiceProvider, NotificationHubServiceOptions> configureHub = null) { NotificationHubServiceOptions notificationHubServiceOptions = new NotificationHubServiceOptions(serviceCollection); configureHub?.Invoke(serviceCollection.BuildServiceProvider(), notificationHubServiceOptions); serviceCollection.AddScoped <NotificationHubServiceOptions>(options => notificationHubServiceOptions); serviceCollection.AddScoped <NotificationHubService>(); }