2015-08-24 46 views
2

我有一个web api应用程序,包含一些SignalR功能,它具有由Autofac管理的依赖关系。SignalR,WebApi,Autofac,camelCasedJson

SignalR,开箱即用,不支持camelCased Json属性。

有一个体面的修复here,但我需要将它与Autofac集成。

所以.....

这里的SignalR枢纽

public class PledgeHub : Hub 
{ 
    public void SendPledge(LivePledgeUpdate pledge) 
    { 
     Clients.All.sendPledge(pledge); 
    } 
} 

这里的startup.cs类从文章

​​

inluding的驼峰格式解析器我刚刚得到驼峰特性所有通过WebApi提供的服务都可以,但不能通过Signalr。

回答

1

我猜,你的问题是这样的:

GlobalHost.DependencyResolver.Register(typeof(JsonSerializer),() => JsonSerializerFactory.Value); 

如果您使用Autofac作为容器/依赖解析器,你要注册与Autofac序列化,不能与即将TO-被替换的全局依赖解析器。

builder.Register(ctx => JsonSerializerFactory.Value).As<JsonSerializer>(); 

此外,我看到你正在使用OWIN。当您使用OWIN时,您不会引用GlobalHost - 您分别设置了集线器配置。 The docs have an example showing how to do it

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
    var builder = new ContainerBuilder(); 

    // STANDARD SIGNALR SETUP: 

    // Get your HubConfiguration. In OWIN, you'll create one 
    // rather than using GlobalHost. 
    var config = new HubConfiguration(); 

    // Register your SignalR hubs. 
    builder.RegisterHubs(Assembly.GetExecutingAssembly()); 

    // Set the dependency resolver to be Autofac. 
    var container = builder.Build(); 
    config.Resolver = new AutofacDependencyResolver(container); 

    // OWIN SIGNALR SETUP: 

    // Register the Autofac middleware FIRST, then the standard SignalR middleware. 
    app.UseAutofacMiddleware(container); 
    app.MapSignalR("/signalr", config); 
    } 
} 
+0

谢谢,可能需要几天时间我才能检查结果并标记为正确。我知道这将与全局主机有关,只是不确定注册该串行器的语法。 – MrBliz

+0

这对我不起作用。它注册一切正常,但串行器似乎搞乱了通信。一旦我有了序列化程序,来自主机的消息就不会再向客户端发送消息了。 @MrBliz你能分享一下你是否有这个固定的? – Jasper

+0

我没有。我结束了客户端上的pascal套件 – MrBliz