私は、Autofacで動作するSignalRを取得しようとしています。IHubContextの自動注入SignalR MVC
https://github.com/justsayno/signalr-autofac
これが適応されたGlobalHost
使用して動作します:私はここでやっている私はの背中取り除いたバージョンのレポを持ってうまく使った作品
https://github.com/sstorie/experiments/tree/master/angular2-signalr
HTE GlobalHostオブジェクト。私は、SignalFサービスを注入する方法についてAutofacのサイトのドキュメントに従ってみようとしましたが、動作させることができません。これは私の依存関係を登録するための私の設定ファイルである:
public static IContainer RegisterDependencies()
{
// Create your builder.
var builder = new ContainerBuilder();
//register controllers in DI
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
// Register SignalR hubs
builder.RegisterHubs(Assembly.GetExecutingAssembly());
return builder.Build();
}
そして私はstartup.csからこれを呼び出す:
public class Startup
{
public static IContainer Container { get; set; }
public void Configuration(IAppBuilder app)
{
var config = GlobalConfiguration.Configuration;
// configure IoC container
Container = AutofacConfiguration.RegisterDependencies();
//set dependency resolver from WebAPI and MVC
config.DependencyResolver = new AutofacWebApiDependencyResolver(Container);
DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(Container));
//register Autofac Middleware
app.UseAutofacMiddleware(Container);
app.Map("/signalr", a =>
{
a.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
Resolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(Container)
};
a.RunSignalR(hubConfiguration);
});
// This server will be accessed by clients from other domains, so
// we open up CORS
//
app.UseCors(CorsOptions.AllowAll);
// Build up the WebAPI middleware
//
var httpConfig = new HttpConfiguration();
httpConfig.MapHttpAttributeRoutes();
app.UseWebApi(httpConfig);
}
}
そして、私は、これはそのコンストラクタの内容に注入したコントローラがあります。
public TaskController(IHubContext hubContext)
{
// Commented out hard coded global host version
//
//_context = GlobalHost.ConnectionManager.GetHubContext<EventHub>();
// using DI
_context = hubContext;
}
を
これは、コントローラがデフォルトのコンストラクタを持っていないというエラーです。(これは私のIHubContextが見つからないという問題です。
助けがあれば助かります。私はそのことについて話しています何のレポは、完全なソリューションのためにここで見つけることができます作られています
https://github.com/justsayno/signalr-autofac
Thanks Sam。名前付き属性をハブ自体に追加する必要がありますか?それともクラス名を使用していますか? – sethreidnz
登録時にGetHubContext <>()呼び出しで使用したクラスを使用する必要があります。私が信じるハブ自体に何かを加える必要はありません。 –