我使用Unity作爲我的DI容器,在解析SignalR集線器時我無法使其工作。有沒有人有過這個成功?我已經試過如下:使用UnityContainer作爲SignalR依賴關係解析器
public class UnityDependencyResolver : DefaultDependencyResolver
{
private readonly IUnityContainer _Container;
public UnityDependencyResolver (IUnityContainer container)
{
_Container = container;
//edit to add
container.RegisterInstance<IJavaScriptMinifier>(NullJavaScriptMinifier.Instance);
}
public override object GetService(Type serviceType)
{
return base.GetService(serviceType) ?? _Container.Resolve(serviceType);
}
public override IEnumerable<object> GetServices(Type serviceType)
{
return base.GetServices(serviceType) ?? _Container.ResolveAll(serviceType);
}
}
,但我發現指示錯誤無法解析SignalR.Infrastructure.IJavaScriptMinifier
您是否註冊過使用Unity的'IJavaScriptMinifier'實現? – 2012-03-15 08:37:02
我發佈這個後,我試過,但它感覺像一個黑客。 (我將編輯帖子以顯示如何)。我沒有明確地使用它,它是一個SignalR接口。 – timDunham 2012-03-15 12:52:51
也許你沒有明確地在你的應用程序中使用它。但是如果你的基礎設施依賴於它並且SignalR使用'DependencyResolver'來實現'IJavaScriptMinifier'的實現,你需要在你的容器中註冊它。我不會將它註冊到解析器的構造函數中,而是與您應用程序的應用程序根目錄中的所有其他依賴項一起註冊。 – 2012-03-15 13:35:45