我使用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