I'm using Unity as my DI Container and I haven't been able to get it to work when resolving my SignalR hubs. Has anyone had success with this? I've tried the following:
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);
}
}
but I'm getting an error indicating it can't resolve SignalR.Infrastructure.IJavaScriptMinifier
IJavaScriptMinifier
with Unity? – Sebastian WeberDependencyResolver
to get an implementation of theIJavaScriptMinifier
you need to register it in your container. I would not register it inside the constructor of the resolver but together with all your other dependencies in the application root of your app. – Sebastian WeberDefaultDependencyResolver
is not able to serve a given service. Is there any kind ofInitialize
routine in the default resolver that does not get called by your custom resolver? – Sebastian Weber