2013-03-24 04:16:00 +00:00
|
|
|
|
using System.Data;
|
2013-03-03 22:26:41 +00:00
|
|
|
|
using System.IO;
|
2013-01-19 04:46:43 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Autofac;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
2013-03-30 22:43:19 +00:00
|
|
|
|
using NzbDrone.Common.Eventing;
|
2013-01-19 04:46:43 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-02-24 23:47:57 +00:00
|
|
|
|
using NzbDrone.Core.ExternalNotification;
|
2013-03-07 03:45:36 +00:00
|
|
|
|
using NzbDrone.Core.IndexerSearch;
|
2013-02-23 04:37:23 +00:00
|
|
|
|
using NzbDrone.Core.Indexers;
|
2013-01-19 04:46:43 +00:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core
|
|
|
|
|
{
|
2013-03-05 05:51:07 +00:00
|
|
|
|
public static class ContainerExtensions
|
2013-01-19 04:46:43 +00:00
|
|
|
|
{
|
|
|
|
|
|
2013-01-19 18:54:00 +00:00
|
|
|
|
private static readonly Logger logger = LogManager.GetLogger("ServiceRegistration");
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
2013-01-20 00:19:27 +00:00
|
|
|
|
public static void RegisterCoreServices(this ContainerBuilder containerBuilder)
|
2013-01-19 04:46:43 +00:00
|
|
|
|
{
|
2013-02-19 07:20:51 +00:00
|
|
|
|
containerBuilder.RegisterAssembly("NzbDrone.Common");
|
2013-02-19 01:57:08 +00:00
|
|
|
|
containerBuilder.RegisterAssembly("NzbDrone.Core");
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
2013-01-20 00:19:27 +00:00
|
|
|
|
containerBuilder.InitDatabase();
|
2013-03-30 22:43:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
containerBuilder.RegisterType<EventAggregator>()
|
|
|
|
|
.As<IEventAggregator>().SingleInstance();
|
|
|
|
|
|
2013-01-20 00:19:27 +00:00
|
|
|
|
containerBuilder.RegisterModule<LogInjectionModule>();
|
2013-01-19 04:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-19 01:57:08 +00:00
|
|
|
|
private static void RegisterAssembly(this ContainerBuilder container, string assemblyName)
|
2013-01-19 04:46:43 +00:00
|
|
|
|
{
|
2013-01-19 19:42:06 +00:00
|
|
|
|
|
2013-02-19 01:57:08 +00:00
|
|
|
|
container.RegisterAssemblyTypes(assemblyName);
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
2013-02-19 01:57:08 +00:00
|
|
|
|
var assembly = Assembly.Load(assemblyName);
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
|
|
|
|
container.RegisterAssemblyTypes(assembly)
|
2013-01-19 18:54:00 +00:00
|
|
|
|
.Where(t => t.IsSubclassOf(typeof(IndexerBase)))
|
2013-03-30 22:14:33 +00:00
|
|
|
|
.As<IndexerBase>();
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
|
|
|
|
container.RegisterAssemblyTypes(assembly)
|
2013-03-07 04:34:56 +00:00
|
|
|
|
.Where(t => t.IsSubclassOf(typeof(IndexerSearchBase)))
|
2013-03-30 22:14:33 +00:00
|
|
|
|
.As<IndexerSearchBase>();
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
|
|
|
|
container.RegisterAssemblyTypes(assembly)
|
2013-01-19 18:54:00 +00:00
|
|
|
|
.Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase)))
|
2013-03-30 22:14:33 +00:00
|
|
|
|
.As<ExternalNotificationBase>();
|
2013-01-19 04:46:43 +00:00
|
|
|
|
}
|
2013-01-19 19:42:06 +00:00
|
|
|
|
|
2013-01-19 04:46:43 +00:00
|
|
|
|
private static void InitDatabase(this ContainerBuilder container)
|
|
|
|
|
{
|
2013-01-19 18:54:00 +00:00
|
|
|
|
logger.Info("Registering Database...");
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
2013-03-25 04:36:24 +00:00
|
|
|
|
var environmentProvider = new EnvironmentProvider();
|
|
|
|
|
var appDataPath = environmentProvider.GetAppDataPath();
|
2013-01-19 04:46:43 +00:00
|
|
|
|
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
|
|
|
|
|
|
2013-03-30 22:14:33 +00:00
|
|
|
|
container.Register(c => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase())).As<IDatabase>();
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
2013-02-17 05:09:35 +00:00
|
|
|
|
container.RegisterGeneric(typeof(BasicRepository<>)).As(typeof(IBasicRepository<>));
|
2013-01-19 04:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|