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