Changed the way the Database is registered with TinyIoC to make Logdb and future cachedb more accessible.

pull/241/merge
Taloth Saldono 10 years ago
parent 4ca8178ca8
commit 2a83088045

@ -15,14 +15,14 @@ namespace NzbDrone.Api.System
private readonly IRuntimeInfo _runtimeInfo;
private readonly IRouteCacheProvider _routeCacheProvider;
private readonly IConfigFileProvider _configFileProvider;
private readonly IDatabase _database;
private readonly IMainDatabase _database;
private readonly ILifecycleService _lifecycleService;
public SystemModule(IAppFolderInfo appFolderInfo,
IRuntimeInfo runtimeInfo,
IRouteCacheProvider routeCacheProvider,
IConfigFileProvider configFileProvider,
IDatabase database,
IMainDatabase database,
ILifecycleService lifecycleService)
: base("system")
{

@ -12,30 +12,42 @@ using NzbDrone.Host;
using NzbDrone.Test.Common;
using FluentAssertions;
using System.Linq;
using NzbDrone.Common.Composition;
using NzbDrone.Core.Datastore;
namespace NzbDrone.App.Test
{
[TestFixture]
public class ContainerFixture : TestBase
{
StartupContext args = new StartupContext("first", "second");
private IContainer _container;
[SetUp]
public void SetUp()
{
var args = new StartupContext("first", "second");
_container = MainAppContainerBuilder.BuildContainer(args);
_container.Register<IMainDatabase>(new MainDatabase(null));
}
[Test]
public void should_be_able_to_resolve_indexers()
{
MainAppContainerBuilder.BuildContainer(args).Resolve<IEnumerable<IIndexer>>().Should().NotBeEmpty();
_container.Resolve<IEnumerable<IIndexer>>().Should().NotBeEmpty();
}
[Test]
public void should_be_able_to_resolve_downloadclients()
{
MainAppContainerBuilder.BuildContainer(args).Resolve<IEnumerable<IDownloadClient>>().Should().NotBeEmpty();
_container.Resolve<IEnumerable<IDownloadClient>>().Should().NotBeEmpty();
}
[Test]
public void container_should_inject_itself()
{
var factory = MainAppContainerBuilder.BuildContainer(args).Resolve<IServiceFactory>();
var factory = _container.Resolve<IServiceFactory>();
factory.Build<IIndexerFactory>().Should().NotBeNull();
}
@ -44,9 +56,8 @@ namespace NzbDrone.App.Test
public void should_resolve_command_executor_by_name()
{
var genericExecutor = typeof(IExecute<>).MakeGenericType(typeof(RssSyncCommand));
var container = MainAppContainerBuilder.BuildContainer(args);
var executor = container.Resolve(genericExecutor);
var executor = _container.Resolve(genericExecutor);
executor.Should().NotBeNull();
executor.Should().BeAssignableTo<IExecute<RssSyncCommand>>();
@ -56,10 +67,8 @@ namespace NzbDrone.App.Test
[Ignore("need to fix this at some point")]
public void should_return_same_instance_of_singletons()
{
var container = MainAppContainerBuilder.BuildContainer(args);
var first = container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single();
var second = container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single();
var first = _container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single();
var second = _container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single();
first.Should().BeSameAs(second);
}

@ -13,7 +13,7 @@ namespace NzbDrone.Core.Authentication
public class UserRepository : BasicRepository<User>, IUserRepository
{
public UserRepository(IDatabase database, IEventAggregator eventAggregator)
public UserRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -24,7 +24,7 @@ namespace NzbDrone.Core.Backup
public class BackupService : IBackupService, IExecute<BackupCommand>
{
private readonly IDatabase _maindDb;
private readonly IMainDatabase _maindDb;
private readonly IDiskProvider _diskProvider;
private readonly IAppFolderInfo _appFolderInfo;
private readonly IArchiveService _archiveService;
@ -34,7 +34,7 @@ namespace NzbDrone.Core.Backup
private static readonly Regex BackupFileRegex = new Regex(@"nzbdrone_backup_[._0-9]+\.zip", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public BackupService(IDatabase maindDb,
public BackupService(IMainDatabase maindDb,
IDiskProvider diskProvider,
IAppFolderInfo appFolderInfo,
IArchiveService archiveService,

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Blacklisting
public class BlacklistRepository : BasicRepository<Blacklist>, IBlacklistRepository
{
public BlacklistRepository(IDatabase database, IEventAggregator eventAggregator) :
public BlacklistRepository(IMainDatabase database, IEventAggregator eventAggregator) :
base(database, eventAggregator)
{
}

@ -13,7 +13,7 @@ namespace NzbDrone.Core.Configuration
public class ConfigRepository : BasicRepository<Config>, IConfigRepository
{
public ConfigRepository(IDatabase database, IEventAggregator eventAggregator)
public ConfigRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -13,7 +13,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
public class SceneMappingRepository : BasicRepository<SceneMapping>, ISceneMappingRepository
{
public SceneMappingRepository(IDatabase database, IEventAggregator eventAggregator)
public SceneMappingRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -28,13 +28,13 @@ namespace NzbDrone.Core.Datastore
public static void RegisterDatabase(IContainer container)
{
var mainDb = container.Resolve<IDbFactory>().Create();
var mainDb = new MainDatabase(container.Resolve<IDbFactory>().Create());
container.Register(mainDb);
container.Register<IMainDatabase>(mainDb);
var logDb = container.Resolve<IDbFactory>().Create(MigrationType.Log);
var logDb = new LogDatabase(container.Resolve<IDbFactory>().Create(MigrationType.Log));
container.Register<ILogRepository>(c => new LogRepository(logDb, c.Resolve<IEventAggregator>()));
container.Register<ILogDatabase>(logDb);
}
public DbFactory(IMigrationController migrationController, IConnectionStringFactory connectionStringFactory)

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Marr.Data;
namespace NzbDrone.Core.Datastore
{
public interface ILogDatabase : IDatabase
{
}
public class LogDatabase : ILogDatabase
{
private readonly IDatabase _database;
public LogDatabase(IDatabase database)
{
_database = database;
}
public IDataMapper GetDataMapper()
{
return _database.GetDataMapper();
}
public Version Version
{
get { return _database.Version; }
}
public void Vacuum()
{
_database.Vacuum();
}
}
}

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Marr.Data;
namespace NzbDrone.Core.Datastore
{
public interface IMainDatabase : IDatabase
{
}
public class MainDatabase : IMainDatabase
{
private readonly IDatabase _database;
public MainDatabase(IDatabase database)
{
_database = database;
}
public IDataMapper GetDataMapper()
{
return _database.GetDataMapper();
}
public Version Version
{
get { return _database.Version; }
}
public void Vacuum()
{
_database.Vacuum();
}
}
}

@ -55,7 +55,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
switch (Context.MigrationType)
{
case MigrationType.Main:
_logger.Info("Starting migration to " + Version);
_logger.Info("Starting migration to " + Version);
MainDbUpgrade();
return;
case MigrationType.Log:

@ -11,7 +11,7 @@ namespace NzbDrone.Core.Download
public class DownloadClientRepository : ProviderRepository<DownloadClientDefinition>, IDownloadClientRepository
{
public DownloadClientRepository(IDatabase database, IEventAggregator eventAggregator)
public DownloadClientRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -13,7 +13,7 @@ namespace NzbDrone.Core.Download.Pending
public class PendingReleaseRepository : BasicRepository<PendingRelease>, IPendingReleaseRepository
{
public PendingReleaseRepository(IDatabase database, IEventAggregator eventAggregator)
public PendingReleaseRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -20,7 +20,7 @@ namespace NzbDrone.Core.History
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
{
public HistoryRepository(IDatabase database, IEventAggregator eventAggregator)
public HistoryRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -4,9 +4,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupAdditionalNamingSpecs : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CleanupAdditionalNamingSpecs(IDatabase database)
public CleanupAdditionalNamingSpecs(IMainDatabase database)
{
_database = database;
}

@ -4,9 +4,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupDuplicateMetadataFiles : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CleanupDuplicateMetadataFiles(IDatabase database)
public CleanupDuplicateMetadataFiles(IMainDatabase database)
{
_database = database;
}

@ -4,9 +4,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupOrphanedBlacklist : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CleanupOrphanedBlacklist(IDatabase database)
public CleanupOrphanedBlacklist(IMainDatabase database)
{
_database = database;
}

@ -5,9 +5,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupOrphanedEpisodeFiles : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CleanupOrphanedEpisodeFiles(IDatabase database)
public CleanupOrphanedEpisodeFiles(IMainDatabase database)
{
_database = database;
}

@ -5,9 +5,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupOrphanedEpisodes : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CleanupOrphanedEpisodes(IDatabase database)
public CleanupOrphanedEpisodes(IMainDatabase database)
{
_database = database;
}

@ -4,9 +4,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupOrphanedHistoryItems : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CleanupOrphanedHistoryItems(IDatabase database)
public CleanupOrphanedHistoryItems(IMainDatabase database)
{
_database = database;
}

@ -4,9 +4,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupOrphanedMetadataFiles : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CleanupOrphanedMetadataFiles(IDatabase database)
public CleanupOrphanedMetadataFiles(IMainDatabase database)
{
_database = database;
}

@ -4,9 +4,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupOrphanedPendingReleases : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CleanupOrphanedPendingReleases(IDatabase database)
public CleanupOrphanedPendingReleases(IMainDatabase database)
{
_database = database;
}

@ -7,10 +7,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class FixFutureRunScheduledTasks : IHousekeepingTask
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
private readonly Logger _logger;
public FixFutureRunScheduledTasks(IDatabase database, Logger logger)
public FixFutureRunScheduledTasks(IMainDatabase database, Logger logger)
{
_database = database;
_logger = logger;

@ -13,9 +13,9 @@ namespace NzbDrone.Core.Housekeeping
{
private readonly IEnumerable<IHousekeepingTask> _housekeepers;
private readonly Logger _logger;
private readonly IDatabase _mainDb;
private readonly IMainDatabase _mainDb;
public HousekeepingService(IEnumerable<IHousekeepingTask> housekeepers, IDatabase mainDb, Logger logger)
public HousekeepingService(IEnumerable<IHousekeepingTask> housekeepers, IMainDatabase mainDb, Logger logger)
{
_housekeepers = housekeepers;
_logger = logger;

@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers
public class IndexerRepository : ProviderRepository<IndexerDefinition>, IIndexerRepository
{
public IndexerRepository(IDatabase database, IEventAggregator eventAggregator)
public IndexerRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Instrumentation
public class LogRepository : BasicRepository<Log>, ILogRepository
{
public LogRepository(IDatabase database, IEventAggregator eventAggregator)
public LogRepository(ILogDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -15,7 +15,7 @@ namespace NzbDrone.Core.Jobs
public class ScheduledTaskRepository : BasicRepository<ScheduledTask>, IScheduledTaskRepository
{
public ScheduledTaskRepository(IDatabase database, IEventAggregator eventAggregator)
public ScheduledTaskRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -15,7 +15,7 @@ namespace NzbDrone.Core.MediaFiles
public class MediaFileRepository : BasicRepository<EpisodeFile>, IMediaFileRepository
{
public MediaFileRepository(IDatabase database, IEventAggregator eventAggregator)
public MediaFileRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -20,9 +20,9 @@ namespace NzbDrone.Core.Messaging.Commands
public class CommandRepository : BasicRepository<CommandModel>, ICommandRepository
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public CommandRepository(IDatabase database, IEventAggregator eventAggregator)
public CommandRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
_database = database;

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Metadata
public class MetadataRepository : ProviderRepository<MetadataDefinition>, IMetadataRepository
{
public MetadataRepository(IDatabase database, IEventAggregator eventAggregator)
public MetadataRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -18,7 +18,7 @@ namespace NzbDrone.Core.Metadata.Files
public class MetadataFileRepository : BasicRepository<MetadataFile>, IMetadataFileRepository
{
public MetadataFileRepository(IDatabase database, IEventAggregator eventAggregator)
public MetadataFileRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Notifications
public class NotificationRepository : ProviderRepository<NotificationDefinition>, INotificationRepository
{
public NotificationRepository(IDatabase database, IEventAggregator eventAggregator)
public NotificationRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -172,6 +172,8 @@
<Compile Include="Datastore\Extensions\RelationshipExtensions.cs" />
<Compile Include="Datastore\IEmbeddedDocument.cs" />
<Compile Include="Datastore\LazyList.cs" />
<Compile Include="Datastore\MainDatabase.cs" />
<Compile Include="Datastore\LogDatabase.cs" />
<Compile Include="Datastore\Migration\001_initialSetup.cs" />
<Compile Include="Datastore\Migration\002_remove_tvrage_imdb_unique_constraint.cs" />
<Compile Include="Datastore\Migration\003_remove_clean_title_from_scene_mapping.cs" />
@ -670,6 +672,7 @@
<Compile Include="Notifications\Synology\SynologyIndexer.cs" />
<Compile Include="Notifications\Synology\SynologyIndexerProxy.cs" />
<Compile Include="Notifications\Synology\SynologyIndexerSettings.cs" />
<Compile Include="Organizer\NamingConfigRepository.cs" />
<Compile Include="Profiles\Delay\DelayProfile.cs" />
<Compile Include="Profiles\Delay\DelayProfileService.cs" />
<Compile Include="Profiles\Delay\DelayProfileTagInUseValidator.cs" />

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Organizer
{
public interface INamingConfigRepository : IBasicRepository<NamingConfig>
{
}
public class NamingConfigRepository : BasicRepository<NamingConfig>, INamingConfigRepository
{
public NamingConfigRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
}
}

@ -10,9 +10,9 @@ namespace NzbDrone.Core.Organizer
public class NamingConfigService : INamingConfigService
{
private readonly IBasicRepository<NamingConfig> _repository;
private readonly INamingConfigRepository _repository;
public NamingConfigService(IBasicRepository<NamingConfig> repository)
public NamingConfigService(INamingConfigRepository repository)
{
_repository = repository;
}

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Profiles.Delay
public class DelayProfileRepository : BasicRepository<DelayProfile>, IDelayProfileRepository
{
public DelayProfileRepository(IDatabase database, IEventAggregator eventAggregator)
public DelayProfileRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Profiles
public class ProfileRepository : BasicRepository<Profile>, IProfileRepository
{
public ProfileRepository(IDatabase database, IEventAggregator eventAggregator)
public ProfileRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Qualities
public class QualityDefinitionRepository : BasicRepository<QualityDefinition>, IQualityDefinitionRepository
{
public QualityDefinitionRepository(IDatabase database, IEventAggregator eventAggregator)
public QualityDefinitionRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -11,7 +11,7 @@ namespace NzbDrone.Core.RemotePathMappings
public class RemotePathMappingRepository : BasicRepository<RemotePathMapping>, IRemotePathMappingRepository
{
public RemotePathMappingRepository(IDatabase database, IEventAggregator eventAggregator)
public RemotePathMappingRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -9,7 +9,7 @@ namespace NzbDrone.Core.Restrictions
public class RestrictionRepository : BasicRepository<Restriction>, IRestrictionRepository
{
public RestrictionRepository(IDatabase database, IEventAggregator eventAggregator)
public RestrictionRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -11,7 +11,7 @@ namespace NzbDrone.Core.RootFolders
public class RootFolderRepository : BasicRepository<RootFolder>, IRootFolderRepository
{
public RootFolderRepository(IDatabase database, IEventAggregator eventAggregator)
public RootFolderRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -13,9 +13,9 @@ namespace NzbDrone.Core.SeriesStats
public class SeriesStatisticsRepository : ISeriesStatisticsRepository
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
public SeriesStatisticsRepository(IDatabase database)
public SeriesStatisticsRepository(IMainDatabase database)
{
_database = database;
}

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Tags
public class TagRepository : BasicRepository<Tag>, ITagRepository
{
public TagRepository(IDatabase database, IEventAggregator eventAggregator)
public TagRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -7,7 +7,7 @@ namespace NzbDrone.Core.ThingiProvider
where TProviderDefinition : ModelBase,
new()
{
protected ProviderRepository(IDatabase database, IEventAggregator eventAggregator)
protected ProviderRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -34,10 +34,10 @@ namespace NzbDrone.Core.Tv
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
{
private readonly IDatabase _database;
private readonly IMainDatabase _database;
private readonly Logger _logger;
public EpisodeRepository(IDatabase database, IEventAggregator eventAggregator, Logger logger)
public EpisodeRepository(IMainDatabase database, IEventAggregator eventAggregator, Logger logger)
: base(database, eventAggregator)
{
_database = database;

@ -16,7 +16,7 @@ namespace NzbDrone.Core.Tv
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
{
public SeriesRepository(IDatabase database, IEventAggregator eventAggregator)
public SeriesRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}

@ -41,8 +41,6 @@ namespace NzbDrone.Host
{
AutoRegisterImplementations<NzbDronePersistentConnection>();
Container.Register(typeof(IBasicRepository<NamingConfig>), typeof(BasicRepository<NamingConfig>));
Container.Register<INancyBootstrapper, NancyBootstrapper>();
}
}

Loading…
Cancel
Save