2013-04-20 00:05:48 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
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-05-10 23:53:50 +00:00
|
|
|
|
using NzbDrone.Common.Composition;
|
2013-06-28 00:04:52 +00:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-05-21 03:20:29 +00:00
|
|
|
|
using NzbDrone.Common.Messaging;
|
2013-04-20 00:05:48 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-05-21 03:20:29 +00:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
2013-04-20 00:05:48 +00:00
|
|
|
|
using NzbDrone.Core.Organizer;
|
|
|
|
|
using NzbDrone.Core.RootFolders;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone
|
|
|
|
|
{
|
|
|
|
|
public class MainAppContainerBuilder : ContainerBuilderBase
|
|
|
|
|
{
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilderBase");
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
public static IContainer BuildContainer()
|
2013-04-20 00:05:48 +00:00
|
|
|
|
{
|
|
|
|
|
return new MainAppContainerBuilder().Container;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MainAppContainerBuilder()
|
|
|
|
|
: base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api")
|
|
|
|
|
{
|
2013-05-10 23:53:50 +00:00
|
|
|
|
AutoRegisterImplementations<NzbDronePersistentConnection>();
|
2013-04-20 00:05:48 +00:00
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>));
|
|
|
|
|
Container.Register(typeof(IBasicRepository<NamingConfig>), typeof(BasicRepository<NamingConfig>));
|
2013-04-20 00:05:48 +00:00
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
Container.Register<INancyBootstrapper, NancyBootstrapper>();
|
2013-05-05 21:24:33 +00:00
|
|
|
|
|
2013-04-20 00:05:48 +00:00
|
|
|
|
InitDatabase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitDatabase()
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("Registering Database...");
|
|
|
|
|
|
|
|
|
|
//TODO: move this to factory
|
2013-06-28 00:04:52 +00:00
|
|
|
|
var IAppDirectoryInfo = new AppDirectoryInfo();
|
|
|
|
|
var appDataPath = IAppDirectoryInfo.GetAppDataPath();
|
2013-04-20 00:05:48 +00:00
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(appDataPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(appDataPath);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 00:04:52 +00:00
|
|
|
|
Container.Register(c => c.Resolve<IDbFactory>().Create(IAppDirectoryInfo.GetNzbDroneDatabase()));
|
2013-05-21 03:20:29 +00:00
|
|
|
|
|
|
|
|
|
Container.Register<ILogRepository>(c =>
|
|
|
|
|
{
|
2013-06-28 00:04:52 +00:00
|
|
|
|
var db = c.Resolve<IDbFactory>().Create(IAppDirectoryInfo.GetLogDatabase(), MigrationType.Log);
|
2013-05-21 03:20:29 +00:00
|
|
|
|
return new LogRepository(db, c.Resolve<IMessageAggregator>());
|
|
|
|
|
});
|
2013-04-20 00:05:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|