1

私は NancyFx と TinyIoc に少し慣れていませんが、次のようになります。

NanxyFx 内で TinyIocContainer の自動登録を使用して、非常にきちんとした Nancy モジュールに依存関係を注入することができました。それはすべて問題なく機能しています。

しかし、以下のようなシグナルハブの依存関係を登録するにはどうすればよいでしょうか?

Signalr から古典的なエラー メッセージが常に表示されます。

No parameterless constructor defined for this object.

私のセットアップ:

SignalR ハブがあります。

[Hubname("chathub")]
public class ChatHub: Hub {

    private IChat _chat;

    public ChatHub(Chat chat){
      _chat = chat;
    }

}

これは私の依存関係です:

public class Chat: IChat{

    public Chat(IHubConnectionContext clients, IChatRepo repo){
       ...
    }
}

CustomBootstrapper クラスを作成しました。

public class CustomBootstrapper : DefaultNancyBootstrapper
{
    protected override void ApplicationStartup(TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
    {
        base.ApplicationStartup(container, pipelines);
        // I'm hoping the registration below will resolve for the IHubConnectionContext parameter for the Chat class
        container.Register(GlobalHost.ConnectionManager.GetHubContext<ChatHub>().Clients);
    }
}

私はスタートアップクラスを持っています:

 public class Startup{
    var hubConfiguration = new HubConfiguration { EnableDetailedErrors = true};
    app.MapSignalR("/signalr", hubConfiguration);
 }

ChatHub にパラメーターのないコンストラクターがあり、貧弱な Ioc を使用すると、すべて正常に動作します。

私は何かが欠けていると確信しています。

何か案は?

4

1 に答える 1