using System; using System.Linq; using System.Collections.Generic; using NzbDrone.Common.Composition; namespace NzbDrone.Common { public interface IServiceFactory { T Build() where T : class; IEnumerable BuildAll() where T : class; object Build(Type contract); IEnumerable GetImplementations(Type contract); } public class ServiceFactory : IServiceFactory { private readonly IContainer _container; public ServiceFactory(IContainer container) { _container = container; } public T Build() where T : class { return _container.Resolve(); } public IEnumerable BuildAll() where T : class { return _container.ResolveAll().GroupBy(c => c.GetType().FullName).Select(g => g.First()); } public object Build(Type contract) { return _container.Resolve(contract); } public IEnumerable GetImplementations(Type contract) { return _container.GetImplementations(contract); } } }