2013-04-20 00:05:48 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using FluentMigrator.Runner;
|
|
|
|
|
using NLog;
|
|
|
|
|
using Nancy.Bootstrapper;
|
|
|
|
|
using NzbDrone.Api;
|
2013-05-05 21:24:33 +00:00
|
|
|
|
using NzbDrone.Api.SignalR;
|
2013-04-20 00:05:48 +00:00
|
|
|
|
using NzbDrone.Common;
|
2013-04-24 01:56:00 +00:00
|
|
|
|
using NzbDrone.Common.Messaging;
|
2013-04-20 00:05:48 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
|
|
|
|
using NzbDrone.Core.ExternalNotification;
|
|
|
|
|
using NzbDrone.Core.Organizer;
|
|
|
|
|
using NzbDrone.Core.RootFolders;
|
|
|
|
|
using TinyIoC;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone
|
|
|
|
|
{
|
|
|
|
|
public class MainAppContainerBuilder : ContainerBuilderBase
|
|
|
|
|
{
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilderBase");
|
|
|
|
|
|
|
|
|
|
public static TinyIoCContainer BuildContainer()
|
|
|
|
|
{
|
|
|
|
|
return new MainAppContainerBuilder().Container;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MainAppContainerBuilder()
|
|
|
|
|
: base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api")
|
|
|
|
|
{
|
|
|
|
|
AutoRegisterImplementations<ExternalNotificationBase>();
|
|
|
|
|
|
2013-04-24 01:56:00 +00:00
|
|
|
|
Container.Register<IMessageAggregator, MessageAggregator>().AsSingleton();
|
2013-04-20 00:05:48 +00:00
|
|
|
|
Container.Register<INancyBootstrapper, NancyBootstrapper>().AsSingleton();
|
|
|
|
|
Container.Register<IAnnouncer, MigrationLogger>().AsSingleton();
|
|
|
|
|
Container.Register<Router>().AsSingleton();
|
|
|
|
|
|
|
|
|
|
Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>)).AsMultiInstance();
|
2013-04-25 04:27:49 +00:00
|
|
|
|
Container.Register(typeof(IBasicRepository<NamingConfig>), typeof(BasicRepository<NamingConfig>)).AsMultiInstance();
|
2013-04-20 00:05:48 +00:00
|
|
|
|
|
2013-05-05 21:24:33 +00:00
|
|
|
|
AutoRegisterImplementations<NzbDronePersistentConnection>();
|
|
|
|
|
|
2013-04-20 00:05:48 +00:00
|
|
|
|
InitDatabase();
|
|
|
|
|
|
|
|
|
|
ReportingService.RestProvider = Container.Resolve<RestProvider>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitDatabase()
|
|
|
|
|
{
|
|
|
|
|
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((c, p) => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|