Fixed IInitializable registration

I tried to make it all happen in the same method as AutoRegisterImplementations, but it caused issues with BasicRepo.
This commit is contained in:
Mark McDowall 2013-04-05 18:03:14 -07:00
parent 28d4010c5c
commit 9ae21cf7a1
4 changed files with 22 additions and 7 deletions

View File

@ -44,7 +44,7 @@ namespace NzbDrone.Api
private void KickoffInitilizables(TinyIoCContainer container) private void KickoffInitilizables(TinyIoCContainer container)
{ {
var initilizables = container.Resolve<IEnumerable<IInitializable>>(); var initilizables = container.ResolveAll<IInitializable>();
foreach (var initializable in initilizables) foreach (var initializable in initilizables)
{ {

View File

@ -38,14 +38,18 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings"); Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings");
Mapper.Entity<History.History>().RegisterModel("History") Mapper.Entity<History.History>().RegisterModel("History")
.HasOne(h => h.Episode, h => h.EpisodeId); .HasOne(h => h.Episode, h => h.EpisodeId);
Mapper.Entity<Series>().RegisterModel("Series"); Mapper.Entity<Series>().RegisterModel("Series");
Mapper.Entity<Season>().RegisterModel("Seasons"); Mapper.Entity<Season>().RegisterModel("Seasons");
Mapper.Entity<Episode>().RegisterModel("Episodes"); Mapper.Entity<Episode>().RegisterModel("Episodes");
Mapper.Entity<EpisodeFile>().RegisterModel("EpisodeFiles"); Mapper.Entity<EpisodeFile>().RegisterModel("EpisodeFiles");
Mapper.Entity<QualityProfile>().RegisterModel("QualityProfiles").For(q => q.DbAllowed).SetColumnName("Allowed").Ignore(q => q.Allowed);
Mapper.Entity<QualityProfile>().RegisterModel("QualityProfiles")
.For(q => q.DbAllowed).SetColumnName("Allowed")
.Ignore(q => q.Allowed);
Mapper.Entity<QualitySize>().RegisterModel("QualitySizes"); Mapper.Entity<QualitySize>().RegisterModel("QualitySizes");
Mapper.Entity<Log>().RegisterModel("Logs"); Mapper.Entity<Log>().RegisterModel("Logs");

View File

@ -21,7 +21,6 @@ namespace NzbDrone.Core.MetadataSource
return response.Data.Select(MapSeries).ToList(); return response.Data.Select(MapSeries).ToList();
} }
public Series GetSeriesInfo(int tvDbSeriesId) public Series GetSeriesInfo(int tvDbSeriesId)
{ {
var client = BuildClient("show", "summary"); var client = BuildClient("show", "summary");
@ -40,7 +39,6 @@ namespace NzbDrone.Core.MetadataSource
return response.Data.seasons.SelectMany(c => c.episodes).Select(MapEpisode).ToList(); return response.Data.seasons.SelectMany(c => c.episodes).Select(MapEpisode).ToList();
} }
private static IRestClient BuildClient(string resource, string method) private static IRestClient BuildClient(string resource, string method)
{ {
return new RestClient(string.Format("http://api.trakt.tv/{0}/{1}.json/6fc98f83c6a02decd17eb7e13d00e89c", resource, method)); return new RestClient(string.Format("http://api.trakt.tv/{0}/{1}.json/6fc98f83c6a02decd17eb7e13d00e89c", resource, method));

View File

@ -13,6 +13,7 @@ using NzbDrone.Core.Datastore.Migration.Framework;
using NzbDrone.Core.ExternalNotification; using NzbDrone.Core.ExternalNotification;
using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
using TinyIoC; using TinyIoC;
@ -36,6 +37,7 @@ namespace NzbDrone
container.AutoRegisterImplementations<IndexerBase>(); container.AutoRegisterImplementations<IndexerBase>();
container.AutoRegisterImplementations<IndexerSearchBase>(); container.AutoRegisterImplementations<IndexerSearchBase>();
container.AutoRegisterImplementations<ExternalNotificationBase>(); container.AutoRegisterImplementations<ExternalNotificationBase>();
container.AutoRegisterMultipleImplementations<IInitializable>();
container.Register<IEventAggregator, EventAggregator>().AsSingleton(); container.Register<IEventAggregator, EventAggregator>().AsSingleton();
container.Register<INancyBootstrapper, TinyNancyBootstrapper>().AsSingleton(); container.Register<INancyBootstrapper, TinyNancyBootstrapper>().AsSingleton();
@ -88,13 +90,24 @@ namespace NzbDrone
private static void AutoRegisterImplementations(this TinyIoCContainer container, Type contractType) private static void AutoRegisterImplementations(this TinyIoCContainer container, Type contractType)
{ {
var implementations = contractType.Assembly.GetImplementations(contractType); var implementations = contractType.Assembly.GetImplementations(contractType).ToList();
foreach (var implementation in implementations) foreach(var implementation in implementations)
{ {
logger.Trace("Registering {0} as {1}", implementation.Name, contractType.Name); logger.Trace("Registering {0} as {1}", implementation.Name, contractType.Name);
container.Register(contractType, implementation).AsMultiInstance(); container.Register(contractType, implementation).AsMultiInstance();
} }
} }
private static void AutoRegisterMultipleImplementations<TContract>(this TinyIoCContainer container)
{
container.AutoRegisterMultipleImplementations(typeof(TContract));
}
private static void AutoRegisterMultipleImplementations(this TinyIoCContainer container, Type contractType)
{
var implementations = contractType.Assembly.GetImplementations(contractType);
container.RegisterMultiple(contractType, implementations).AsMultiInstance();
}
} }
} }