From 2eb3ead2300650d86b4ee086f663e54d5a5a4b6c Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Wed, 10 Apr 2013 16:44:48 -0700 Subject: [PATCH] fixed indexer setting load/reload. --- NzbDrone.Common/NzbDrone.Common.csproj | 1 - NzbDrone.Common/ReflectionExtentions.cs | 25 ------ .../Datastore/Migration/Migration20130324.cs | 5 +- .../FileSharingTalk/FileSharingTalk.cs | 17 +--- NzbDrone.Core/Indexers/IIndexerBase.cs | 22 +++++ .../Indexers/{BaseIndexer.cs => Indexer.cs} | 29 ++----- NzbDrone.Core/Indexers/IndexerRepository.cs | 12 ++- NzbDrone.Core/Indexers/IndexerService.cs | 2 +- .../Indexers/IndexerSettingProvider.cs | 10 ++- .../Indexers/IndexerSettingUpdatedEvent.cs | 16 ++++ NzbDrone.Core/Indexers/IndexerWithSetting.cs | 30 +++++++ NzbDrone.Core/Indexers/Newznab/Newznab.cs | 2 +- NzbDrone.Core/Indexers/NzbClub/NzbClub.cs | 8 +- NzbDrone.Core/Indexers/NzbIndex/NzbIndex.cs | 4 +- NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs | 12 +-- NzbDrone.Core/Indexers/Nzbx/Nzbx.cs | 2 +- .../Indexers/Omgwtfnzbs/Omgwtfnzbs.cs | 12 +-- NzbDrone.Core/Indexers/Wombles/Wombles.cs | 12 +-- NzbDrone.Core/NzbDrone.Core.csproj | 5 +- ...ainerExtentions.cs => ContainerBuilder.cs} | 81 ++++++++++--------- NzbDrone/NzbDrone.csproj | 2 +- 21 files changed, 160 insertions(+), 149 deletions(-) delete mode 100644 NzbDrone.Common/ReflectionExtentions.cs create mode 100644 NzbDrone.Core/Indexers/IIndexerBase.cs rename NzbDrone.Core/Indexers/{BaseIndexer.cs => Indexer.cs} (54%) create mode 100644 NzbDrone.Core/Indexers/IndexerSettingUpdatedEvent.cs create mode 100644 NzbDrone.Core/Indexers/IndexerWithSetting.cs rename NzbDrone/{CommonContainerExtentions.cs => ContainerBuilder.cs} (50%) diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index 8cf81f56b..4e305b362 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -108,7 +108,6 @@ - diff --git a/NzbDrone.Common/ReflectionExtentions.cs b/NzbDrone.Common/ReflectionExtentions.cs deleted file mode 100644 index 32ce6759a..000000000 --- a/NzbDrone.Common/ReflectionExtentions.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace NzbDrone.Common -{ - public static class ReflectionExtensions - { - public static IEnumerable GetInterfaces(this Assembly assembly) - { - return assembly.GetTypes().Where(c => c.IsInterface); - } - - public static IEnumerable GetImplementations(this Assembly assembly, Type contractType) - { - return assembly.GetTypes() - .Where(implementation => - contractType.IsAssignableFrom(implementation) && - !implementation.IsInterface && - !implementation.IsAbstract - ); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs index 0bc6d1cb4..0ceea2f10 100644 --- a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs +++ b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs @@ -101,14 +101,13 @@ protected override void MainDbUpgrade() Create.TableForModel("IndexerDefinitions") .WithColumn("Enable").AsBoolean() .WithColumn("Name").AsString().Unique() - .WithColumn("Settings").AsString(); + .WithColumn("Settings").AsString().Nullable(); Create.TableForModel("NewznabDefinitions") .WithColumn("Enable").AsBoolean() .WithColumn("Name").AsString().Unique() .WithColumn("Url").AsString() - .WithColumn("ApiKey").AsString().Nullable() - .WithColumn("BuiltIn").AsBoolean(); + .WithColumn("ApiKey").AsString().Nullable(); Create.TableForModel("QualityProfiles") .WithColumn("Name").AsString().Unique() diff --git a/NzbDrone.Core/Indexers/FileSharingTalk/FileSharingTalk.cs b/NzbDrone.Core/Indexers/FileSharingTalk/FileSharingTalk.cs index a8dc63a61..b604a72b5 100644 --- a/NzbDrone.Core/Indexers/FileSharingTalk/FileSharingTalk.cs +++ b/NzbDrone.Core/Indexers/FileSharingTalk/FileSharingTalk.cs @@ -3,27 +3,23 @@ namespace NzbDrone.Core.Indexers.FileSharingTalk { - public class FileSharingTalk : BaseIndexer + public class FileSharingTalk : IndexerWithSetting { - private readonly FileSharingTalkSetting _settings; - public FileSharingTalk(IProviderIndexerSetting settingProvider) + : base(settingProvider) { - _settings = settingProvider.Get(this); } public override IEnumerable RecentFeed { get { - yield return - string.Format( + yield return string.Format( "http://filesharingtalk.com/ng_rss.php?uid={0}&ps={1}&category=tv&subcategory=x264sd,x264720,xvid,webdl720,x2641080", - _settings.Uid, _settings.Secret); + Settings.Uid, Settings.Secret); } } - public override IParseFeed Parser { get @@ -32,11 +28,6 @@ public override IParseFeed Parser } } - public override IIndexerSetting Settings - { - get { return _settings; } - } - public override string Name { get { return "FileSharingTalk"; } diff --git a/NzbDrone.Core/Indexers/IIndexerBase.cs b/NzbDrone.Core/Indexers/IIndexerBase.cs new file mode 100644 index 000000000..6e3b5ec56 --- /dev/null +++ b/NzbDrone.Core/Indexers/IIndexerBase.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +namespace NzbDrone.Core.Indexers +{ + public interface IIndexerBase + { + string Name { get; } + bool EnabledByDefault { get; } + + IEnumerable RecentFeed { get; } + + IParseFeed Parser { get; } + + bool IsConfigured { get; } + + IEnumerable GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber); + IEnumerable GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date); + IEnumerable GetSeasonSearchUrls(string seriesTitle, int seasonNumber); + IEnumerable GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard); + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/BaseIndexer.cs b/NzbDrone.Core/Indexers/Indexer.cs similarity index 54% rename from NzbDrone.Core/Indexers/BaseIndexer.cs rename to NzbDrone.Core/Indexers/Indexer.cs index 32a5abcc1..96e0bad3f 100644 --- a/NzbDrone.Core/Indexers/BaseIndexer.cs +++ b/NzbDrone.Core/Indexers/Indexer.cs @@ -3,27 +3,13 @@ namespace NzbDrone.Core.Indexers { - public interface IIndexerBase + public abstract class Indexer : IIndexerBase { - string Name { get; } - bool EnabledByDefault { get; } - IEnumerable RecentFeed { get; } - - IParseFeed Parser { get; } - - IIndexerSetting Settings { get; } - - IEnumerable GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber); - IEnumerable GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date); - IEnumerable GetSeasonSearchUrls(string seriesTitle, int seasonNumber); - IEnumerable GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard); - } - - public abstract class BaseIndexer : IIndexerBase - { public abstract string Name { get; } + + public virtual bool EnabledByDefault { get @@ -40,14 +26,13 @@ public virtual IParseFeed Parser } } - public virtual IIndexerSetting Settings + public virtual bool IsConfigured { - get - { - return new NullSetting(); - } + get { return true; } } + + public abstract IEnumerable RecentFeed { get; } public abstract IEnumerable GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber); diff --git a/NzbDrone.Core/Indexers/IndexerRepository.cs b/NzbDrone.Core/Indexers/IndexerRepository.cs index f2572d812..9fac1b49a 100644 --- a/NzbDrone.Core/Indexers/IndexerRepository.cs +++ b/NzbDrone.Core/Indexers/IndexerRepository.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Indexers @@ -6,6 +7,7 @@ namespace NzbDrone.Core.Indexers public interface IIndexerRepository : IBasicRepository { IndexerDefinition Get(string name); + IndexerDefinition Find(string name); } public class IndexerRepository : BasicRepository, IIndexerRepository @@ -17,7 +19,13 @@ public IndexerRepository(IDatabase database) public IndexerDefinition Get(string name) { - return Query.Single(i => i.Name.ToLower() == name.ToLower()); + return Query.Single(i => i.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); } + + public IndexerDefinition Find(string name) + { + return Query.SingleOrDefault(i => i.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); + } + } } diff --git a/NzbDrone.Core/Indexers/IndexerService.cs b/NzbDrone.Core/Indexers/IndexerService.cs index 452ddc82e..3f8215cc8 100644 --- a/NzbDrone.Core/Indexers/IndexerService.cs +++ b/NzbDrone.Core/Indexers/IndexerService.cs @@ -38,7 +38,7 @@ public List All() public List GetAvailableIndexers() { var enabled = All().Where(c => c.Enable).Select(c => c.Name); - var configureIndexers = _indexers.Where(c => c.Settings.IsValid); + var configureIndexers = _indexers.Where(c => c.IsConfigured); return configureIndexers.Where(c => enabled.Contains(c.Name)).ToList(); } diff --git a/NzbDrone.Core/Indexers/IndexerSettingProvider.cs b/NzbDrone.Core/Indexers/IndexerSettingProvider.cs index 7c6356d29..d5dddee68 100644 --- a/NzbDrone.Core/Indexers/IndexerSettingProvider.cs +++ b/NzbDrone.Core/Indexers/IndexerSettingProvider.cs @@ -18,8 +18,14 @@ public IndexerSettingProvider(IIndexerRepository indexerRepository) public TSetting Get(IIndexerBase indexer) where TSetting : IIndexerSetting, new() { - var json = _indexerRepository.Get(indexer.Name).Settings; - return JsonConvert.DeserializeObject(json); + var indexerDef = _indexerRepository.Find(indexer.Name); + + if (indexerDef == null || string.IsNullOrWhiteSpace(indexerDef.Settings)) + { + return new TSetting(); + } + + return JsonConvert.DeserializeObject(indexerDef.Settings); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/IndexerSettingUpdatedEvent.cs b/NzbDrone.Core/Indexers/IndexerSettingUpdatedEvent.cs new file mode 100644 index 000000000..a458df257 --- /dev/null +++ b/NzbDrone.Core/Indexers/IndexerSettingUpdatedEvent.cs @@ -0,0 +1,16 @@ +using NzbDrone.Common.Eventing; + +namespace NzbDrone.Core.Indexers +{ + public class IndexerSettingUpdatedEvent : IEvent + { + public string IndexerName { get; private set; } + public IIndexerSetting IndexerSetting { get; private set; } + + public IndexerSettingUpdatedEvent(string indexerName, IIndexerSetting indexerSetting) + { + IndexerName = indexerName; + IndexerSetting = indexerSetting; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/IndexerWithSetting.cs b/NzbDrone.Core/Indexers/IndexerWithSetting.cs new file mode 100644 index 000000000..9fec086f2 --- /dev/null +++ b/NzbDrone.Core/Indexers/IndexerWithSetting.cs @@ -0,0 +1,30 @@ +using System; +using NzbDrone.Common.Eventing; + +namespace NzbDrone.Core.Indexers +{ + public abstract class IndexerWithSetting : + Indexer, + IHandle where TSetting : IIndexerSetting, new() + { + protected IndexerWithSetting(IProviderIndexerSetting settingProvider) + { + Settings = settingProvider.Get(this); + } + + public override bool IsConfigured + { + get { return Settings.IsValid; } + } + + protected TSetting Settings { get; private set; } + + public void Handle(IndexerSettingUpdatedEvent message) + { + if (message.IndexerName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)) + { + Settings = (TSetting)message.IndexerSetting; + } + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 77a776197..6692c758d 100644 --- a/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -4,7 +4,7 @@ namespace NzbDrone.Core.Indexers.Newznab { - public class Newznab : BaseIndexer + public class Newznab : Indexer { private readonly INewznabService _newznabProvider; diff --git a/NzbDrone.Core/Indexers/NzbClub/NzbClub.cs b/NzbDrone.Core/Indexers/NzbClub/NzbClub.cs index efa70e9ce..289d38d28 100644 --- a/NzbDrone.Core/Indexers/NzbClub/NzbClub.cs +++ b/NzbDrone.Core/Indexers/NzbClub/NzbClub.cs @@ -1,16 +1,10 @@ using System; using System.Collections.Generic; -using NzbDrone.Common; -using NzbDrone.Core.Configuration; namespace NzbDrone.Core.Indexers.NzbClub { - public class NzbClub : BaseIndexer + public class NzbClub : Indexer { - public NzbClub(HttpProvider httpProvider, IConfigService configService) - { - } - public override IEnumerable RecentFeed { get diff --git a/NzbDrone.Core/Indexers/NzbIndex/NzbIndex.cs b/NzbDrone.Core/Indexers/NzbIndex/NzbIndex.cs index 395772719..97b2823d0 100644 --- a/NzbDrone.Core/Indexers/NzbIndex/NzbIndex.cs +++ b/NzbDrone.Core/Indexers/NzbIndex/NzbIndex.cs @@ -3,7 +3,7 @@ namespace NzbDrone.Core.Indexers.NzbIndex { - public class NzbIndex : BaseIndexer + public class NzbIndex : Indexer { public override IEnumerable RecentFeed { @@ -76,7 +76,7 @@ public override IEnumerable GetPartialSeasonSearchUrls(string seriesTitl - + } diff --git a/NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs b/NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs index 3cf988a45..90f7592b8 100644 --- a/NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs +++ b/NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs @@ -3,13 +3,13 @@ namespace NzbDrone.Core.Indexers.NzbsRUs { - public class Nzbsrus : BaseIndexer + public class Nzbsrus : IndexerWithSetting { private readonly NzbsrusSetting _setting; - public Nzbsrus(IProviderIndexerSetting settingProvider) + public Nzbsrus(IProviderIndexerSetting settingProvider):base(settingProvider) { - _setting = settingProvider.Get(this); + } public override IEnumerable RecentFeed @@ -23,12 +23,6 @@ public override IEnumerable RecentFeed } } - - public override IIndexerSetting Settings - { - get { return _setting; } - } - public override string Name { get { return "NzbsRUs"; } diff --git a/NzbDrone.Core/Indexers/Nzbx/Nzbx.cs b/NzbDrone.Core/Indexers/Nzbx/Nzbx.cs index fe8880e02..24f68fe15 100644 --- a/NzbDrone.Core/Indexers/Nzbx/Nzbx.cs +++ b/NzbDrone.Core/Indexers/Nzbx/Nzbx.cs @@ -3,7 +3,7 @@ namespace NzbDrone.Core.Indexers.Nzbx { - public class Nzbx : BaseIndexer + public class Nzbx : Indexer { public override string Name { diff --git a/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs b/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs index 8dc1d8703..5c4ea4727 100644 --- a/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs +++ b/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs @@ -3,13 +3,11 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs { - public class Omgwtfnzbs : BaseIndexer + public class Omgwtfnzbs : IndexerWithSetting { - private readonly OmgwtfnzbsSetting _settings; - public Omgwtfnzbs(IProviderIndexerSetting settingProvider) + : base(settingProvider) { - _settings = settingProvider.Get(this); } public override string Name @@ -24,14 +22,10 @@ public override IEnumerable RecentFeed yield return String.Format("http://rss.omgwtfnzbs.org/rss-search.php?catid=19,20&user={0}&api={1}&eng=1", - _settings.Username, _settings.ApiKey); + Settings.Username, Settings.ApiKey); } } - public override IIndexerSetting Settings - { - get { return _settings; } - } public override IEnumerable GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { diff --git a/NzbDrone.Core/Indexers/Wombles/Wombles.cs b/NzbDrone.Core/Indexers/Wombles/Wombles.cs index d27df1a6c..2dbdfe4a0 100644 --- a/NzbDrone.Core/Indexers/Wombles/Wombles.cs +++ b/NzbDrone.Core/Indexers/Wombles/Wombles.cs @@ -3,17 +3,11 @@ namespace NzbDrone.Core.Indexers.Wombles { - public class Wombles : BaseIndexer + public class Wombles : Indexer { public override IEnumerable RecentFeed { - get - { - return new[] - { - string.Format("http://nzb.isasecret.com/rss") - }; - } + get { yield return string.Format("http://nzb.isasecret.com/rss"); } } public override string Name @@ -21,8 +15,6 @@ public override string Name get { return "WomblesIndex"; } } - - public override IEnumerable GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { return new List(); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 91cc462ed..fa855f6e5 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -236,6 +236,9 @@ + + + @@ -254,7 +257,7 @@ - + diff --git a/NzbDrone/CommonContainerExtentions.cs b/NzbDrone/ContainerBuilder.cs similarity index 50% rename from NzbDrone/CommonContainerExtentions.cs rename to NzbDrone/ContainerBuilder.cs index 954d3907a..07eec9ccf 100644 --- a/NzbDrone/CommonContainerExtentions.cs +++ b/NzbDrone/ContainerBuilder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -11,9 +12,7 @@ using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore.Migration.Framework; using NzbDrone.Core.ExternalNotification; -using NzbDrone.Core.IndexerSearch; -using NzbDrone.Core.Indexers; -using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Organizer; using NzbDrone.Core.RootFolders; using TinyIoC; @@ -21,27 +20,31 @@ namespace NzbDrone { public static class ContainerBuilder { - private static readonly Logger logger = LogManager.GetLogger("ContainerBuilder"); - + private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilder"); public static TinyIoCContainer Instance { get; private set; } + private static readonly List NzbDroneTypes; static ContainerBuilder() { var container = new TinyIoCContainer(); - container.AutoRegisterInterfaces("NzbDrone"); - container.AutoRegisterInterfaces("NzbDrone.Common"); - container.AutoRegisterInterfaces("NzbDrone.Core"); - container.AutoRegisterInterfaces("NzbDrone.Api"); + NzbDroneTypes = new List(); + NzbDroneTypes.AddRange(Assembly.Load("NzbDrone").GetTypes()); + NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Common").GetTypes()); + NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Core").GetTypes()); + NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Api").GetTypes()); + + container.AutoRegisterInterfaces(); - container.AutoRegisterImplementations(); container.AutoRegisterImplementations(); container.Register().AsSingleton(); container.Register().AsSingleton(); container.Register().AsSingleton(); + container.Register().AsSingleton(); container.Register(typeof(IBasicRepository), typeof(BasicRepository)).AsMultiInstance(); + container.Register(typeof(IBasicRepository), typeof(BasicRepository)).AsMultiInstance(); container.InitDatabase(); @@ -50,30 +53,23 @@ static ContainerBuilder() private static void InitDatabase(this TinyIoCContainer container) { - logger.Info("Registering Database..."); + Logger.Info("Registering Database..."); //TODO: move this to factory var environmentProvider = new EnvironmentProvider(); var appDataPath = environmentProvider.GetAppDataPath(); - if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath); - - container.Register( - delegate(TinyIoCContainer c, NamedParameterOverloads p) - { - return c.Resolve().Create(environmentProvider.GetNzbDroneDatabase()); - }); - } - - private static void AutoRegisterInterfaces(this TinyIoCContainer container, string assemblyName) - { - var assembly = Assembly.Load(assemblyName); - - if (assembly == null) + + if (!Directory.Exists(appDataPath)) { - throw new ApplicationException("Couldn't load assembly " + assemblyName); + Directory.CreateDirectory(appDataPath); } - var interfaces = assembly.GetInterfaces().Where(c => !c.FullName.StartsWith("Nancy.")); + container.Register((c, p) => c.Resolve().Create(environmentProvider.GetNzbDroneDatabase())); + } + + private static void AutoRegisterInterfaces(this TinyIoCContainer container) + { + var interfaces = NzbDroneTypes.Where(t => t.IsInterface); foreach (var contract in interfaces) { @@ -81,6 +77,7 @@ private static void AutoRegisterInterfaces(this TinyIoCContainer container, stri } } + private static void AutoRegisterImplementations(this TinyIoCContainer container) { container.AutoRegisterImplementations(typeof(TContract)); @@ -88,24 +85,30 @@ private static void AutoRegisterImplementations(this TinyIoCContainer private static void AutoRegisterImplementations(this TinyIoCContainer container, Type contractType) { - var implementations = contractType.Assembly.GetImplementations(contractType).ToList(); + var implementations = GetImplementations(contractType).ToList(); - foreach(var implementation in implementations) + if (implementations.Count == 0) { - logger.Trace("Registering {0} as {1}", implementation.Name, contractType.Name); - container.Register(contractType, implementation).AsMultiInstance(); + return; + } + if (implementations.Count == 1) + { + container.Register(contractType, implementations.Single()).AsMultiInstance(); + } + else + { + container.RegisterMultiple(contractType, implementations).AsMultiInstance(); } } - private static void AutoRegisterMultipleImplementations(this TinyIoCContainer container) + private static IEnumerable GetImplementations(Type contractType) { - container.AutoRegisterMultipleImplementations(typeof(TContract)); - } - - private static void AutoRegisterMultipleImplementations(this TinyIoCContainer container, Type contractType) - { - var implementations = contractType.Assembly.GetImplementations(contractType); - container.RegisterMultiple(contractType, implementations).AsMultiInstance(); + return NzbDroneTypes + .Where(implementation => + contractType.IsAssignableFrom(implementation) && + !implementation.IsInterface && + !implementation.IsAbstract + ); } } } \ No newline at end of file diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 2631d3d1b..1d70a9ea5 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -117,7 +117,7 @@ Component - +