私はSignalRとWindsorCastleを使用してASPNETMVC4プロジェクトで作業しています。mvcコントローラーとWebApiコントローラーが動作し、Castleで正常にインスタンス化していますが、Hub of SignalR内で使用すると、UnitofWorkクラスがインスタンス化されません。
足りないものはありますか?
これは私のコードです:
IocConfigクラス
public static class IocConfig
{
public static IWindsorContainer Container { get; private set; }
public static void RegisterIoc(HttpConfiguration config)
{
// Set the dependency resolver for Web API.
var webApicontainer = new WindsorContainer().Install(new WebWindsorInstaller());
GlobalConfiguration.Configuration.DependencyResolver = new WebApiWindsorDependencyResolver(webApicontainer);
// Set the dependency resolver for Mvc Controllers
Container = new WindsorContainer().Install(new ControllersInstaller());
DependencyResolver.SetResolver(new MvcWindsorDependencyResolver(Container));
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(Container));
var controllerFactory = new WindsorControllerFactory(Container.Kernel);
ControllerBuilder.Current.SetControllerFactory(controllerFactory);
}
}
}
WebWindsorInstallerクラス
internal class WebWindsorInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component
.For<RepositoryFactories>()
.ImplementedBy<RepositoryFactories>()
.LifestyleSingleton());
container.Register(Component
.For<IRepositoryProvider>()
.ImplementedBy<RepositoryProvider>()
.LifestylePerWebRequest());
container.Register(Component
.For<IGdpUow>()
.ImplementedBy<GdpUow>()
.LifestylePerWebRequest());
container.Register(Classes
.FromAssemblyContaining<Api.MessagesController>()
.BasedOn<IHttpController>()
.If(t => t.Name.EndsWith("Controller"))
.LifestylePerWebRequest());
}
ControllerInstallerクラス
public class ControllersInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(FindControllers().Configure(c => c.LifestyleTransient()));
container.Register(Component
.For<RepositoryFactories>()
.ImplementedBy<RepositoryFactories>()
.LifestyleSingleton());
container.Register(Component
.For<IRepositoryProvider>()
.ImplementedBy<RepositoryProvider>()
.LifestylePerWebRequest());
container.Register(Component
.For<IGdpUow>()
.ImplementedBy<GdpUow>()
.LifestylePerWebRequest());
}
private static BasedOnDescriptor FindControllers()
{
return AllTypes.FromThisAssembly()
.BasedOn<IController>()
.If(t => t.Name.EndsWith("Controller"));
}
ハブ
using Microsoft.AspNet.SignalR.Hubs;
[HubName("iServerHub")]
public class IServerHub : Hub
{
protected IGdpUow Uow;
public void Send(string name, string message)
{
var messagesList = Uow.UdsMessages.GetAll();
Clients.All.broadcastMessage(messagesList);
}
}
Sendメソッドでは、Uowはnullです。
コントローラはこの基本クラスから継承されます
public abstract class CustomControllerBase : Controller
{
protected IGdpUow Uow { get; set; }
}
また、コントローラーでUowを使用すると、インスタンス化されます。ハブ内での使用との違いがわかりません。
ノート
ウィンザー城をセットアップしてSignalRで動作させる方法については、こちらの手順に従っていますが、次のエラーが発生するため、テストできません(プロキシを作成できないようです)。
Cannot read property client of undefined
ハブへのプロキシが作成されなかったことを意味します
これが私がサーバーに持っている方法です
パブリッククラスIServerHub:ハブ
そしてクライアントでこのように
var clientServerHub = $ .connection.iServerHub;
ここで動的に作成されたファイルを見ることができます:
/GdpSoftware.Server.Web/signalr/hubs
では、なぜプロキシが作成されないのですか?
これは私のインストーラーファイルです
public class HubsInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component
.For<RepositoryFactories>()
.ImplementedBy<RepositoryFactories>()
.LifestyleSingleton());
container.Register(Component
.For<IRepositoryProvider>()
.ImplementedBy<RepositoryProvider>()
.LifestylePerWebRequest());
container.Register(Component
.For<IGdpUow>()
.ImplementedBy<GdpUow>()
.LifestylePerWebRequest());
container.Register(Classes.FromThisAssembly()
.BasedOn<Hub>()
.LifestyleTransient());
}
}
前もって感謝します!ギレルモ。