简体   繁体   中英

Getting the context from a different assembly

In my project I have different assemblies.

The SignalR hub (and client MVC4 files) live in the Website project.

My hub looks like this:

public class PredictHub : Hub
{
    private readonly IChat _chat;

    public PredictHub(IChat chat)
    {
        _chat = chat;
    }

    public void Chat(String message)
    {
        _chat.AddMessage(message);
    }
}

In my second assembly Business the IChat.cs and Chat.cs live:

public class Chat : IChat
{
    public void AddMessage(String message)
    {
        var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
    }
}

But because Chat.cs is in the Business assembly the ChatHub directive is not known because it's not referenced.

How could this be solved?

仅当SignalR和Chat类处于同一过程中时,才能获取上下文。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM