2013-05-05 21:24:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.AspNet.SignalR;
|
2013-05-06 00:33:43 +00:00
|
|
|
|
using Microsoft.AspNet.SignalR.Json;
|
2013-05-05 21:24:33 +00:00
|
|
|
|
using TinyIoC;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.SignalR
|
|
|
|
|
{
|
|
|
|
|
public class SignalrDependencyResolver : DefaultDependencyResolver
|
|
|
|
|
{
|
|
|
|
|
private readonly TinyIoCContainer _container;
|
|
|
|
|
|
|
|
|
|
public static void Register(TinyIoCContainer container)
|
|
|
|
|
{
|
|
|
|
|
GlobalHost.DependencyResolver = new SignalrDependencyResolver(container);
|
2013-05-06 00:33:43 +00:00
|
|
|
|
|
|
|
|
|
container.Register<IJsonSerializer, Serializer>().AsSingleton();
|
2013-05-05 21:24:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SignalrDependencyResolver(TinyIoCContainer container)
|
|
|
|
|
{
|
|
|
|
|
_container = container;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override object GetService(Type serviceType)
|
|
|
|
|
{
|
|
|
|
|
return _container.CanResolve(serviceType) ? _container.Resolve(serviceType) : base.GetService(serviceType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<object> GetServices(Type serviceType)
|
|
|
|
|
{
|
|
|
|
|
var objects = _container.CanResolve(serviceType) ? _container.ResolveAll(serviceType) : new object[] { };
|
|
|
|
|
return objects.Concat(base.GetServices(serviceType));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|