User540216268 posted
I think I`m bit lost: I have a signalr hub which gets a "scoped" service ("subscription-service") injected via DI. This "subscription-service" service gets a hubxontext and additional "scoped" domain-specific services injected, and tries to subscribe to
the different domain-specific observables, that the services provides. In the individual callbacks from the observables, I want to call methods on the hubcontext, to be able to notify the client when CRUD operations has been done.
My proble is that the callbacks are only fired IF the injected domain-services are of "singletons" lifetime.
In my Startup.cs I have configured all my services as "scoped":
services.AddScoped<IMaterialTypeService, MaterialTypeService>();
services.AddScoped<IMaterialTypeRepository, MaterialTypeDbRepository>();
services.AddScoped<WebApiSubscriptionService>();
services.AddScoped<IEmailService, EmailService>();
services.AddScoped<INotificationService, NotificationService>();
The method for wiring up the subscriptions (in the "subscription-service") is as following:
private void Startup()
{
_notificationService.Notifications.Subscribe(notification =>
{
_hubContext.Clients.All.Notify(notification);
});
_materialTypeService.MaterialTypesChanged.Subscribe(materialTypes =>
{
var matTypes = _mapper.Map<IList<MaterialTypeResponseDto>>(materialTypes);
_hubContext.Clients.All.MaterialTypesChanged(matTypes);
});
}
What am I missing in here?
Also, is there a decent boilerplate web app that will show how this should be done?