How to set Json Serializer settings in SignalR2?

I am using Signalr 2, Webapi 2 and Ninject for Ioc and I am having problems.

In SignalR 2.0, you cannot replace JsonSerializer. As said here: SignalR 2.0.0 beta2 Extension IJsonSerializer

I need to ignore ReferenceLoopHandling in json, so I used this code:

var serializerSettings = new JsonSerializerSettings
        {
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
            NullValueHandling = NullValueHandling.Ignore
        };
        GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => JsonSerializer.Create(serializerSettings));

Everything works fine, but I also call signalR clients from Webapi, and the call will not work unless I install this code at the beginning of the application:

GlobalHost.DependencyResolver = new NinjectSignalRDependencyResolver(NinjectIocConfig.Kernel);

Calling caller clients from webapi now works, but JSON serialization options are no longer used.

How can I get around this or what am I doing wrong?

Thank you in advance

+4
2

?

https://github.com/SignalR/SignalR/issues/500#issuecomment-27480715

, kernel.TryGet(serviceType) null, , singalR , Ninject .

, , SignalR Dep.resolver

kernel.GetBindings(serviceType).Any();
+2

2 . [JsonIgnore] , , Json.net .

0

Source: https://habr.com/ru/post/1527104/


All Articles