örneğine ayarlanmadı atar.Hub.Clients.User (kullanıcı kimliği) .methodCall her zaman nesne başvurusu I Hub sınıfından devralan bir NotificationHub sınıfı bir nesnenin
Çalışıyorpublic class NotificationHub : Hub
{
public void Send(string userId, Notification notification)
{
var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.User(userId)
.notificationReceived(notification);
}
}
.... burada ne verir:
public class NotificationHub : Hub
{
public void Send(string userId, Notification notification)
{
Clients.User(userId)
.notificationReceived(notification);
}
}
Bu her zaman bunu Bununla eğer
[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.AspNet.SignalR.Hubs.SignalProxy.Invoke(String method, Object[] args) +88
Microsoft.AspNet.SignalR.Hubs.SignalProxy.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) +12
CallSite.Target(Closure , CallSite , Object , <>f__AnonymousType0`4) +351
ile başarısız? Gördüğüm örneklerin çoğu, içeriği Hub'dan temin edilmemeli, bağlamı almayı gerektirmiyor mu? Her seferinde açıkça ele almak zorunda kalmamayı tercih ederim.
İşte benim IoC Kurulum geçerli:
GlobalHost.DependencyResolver.Register(typeof(IHubActivator),() => new SimpleInjectorHubActivator(container));
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider),() => new SignalRHubUserIdProvider());
Aktivatör:
public class SimpleInjectorHubActivator : IHubActivator
{
private readonly Container _container;
public SimpleInjectorHubActivator(Container container)
{
_container = container;
}
public IHub Create(HubDescriptor descriptor)
{
return (IHub) _container.GetInstance(descriptor.HubType);
}
}
istemciden veya farklı sunucu koddan alıyorsanız NullReferenceException' 'bu çağırıyor' Gönder() 'yöntemi? –
Sunucudan çağrı yapıldığında, Clients.User (userId) .notificationReceived (bildirim); istisna atar – Jack