You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/NzbDrone.Core/ContainerExtensions.cs

69 lines
2.3 KiB

12 years ago
using System.Data;
using System.IO;
using System.Reflection;
using Autofac;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Eventing;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.ExternalNotification;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Instrumentation;
namespace NzbDrone.Core
{
public static class ContainerExtensions
{
12 years ago
private static readonly Logger logger = LogManager.GetLogger("ServiceRegistration");
public static void RegisterCoreServices(this ContainerBuilder containerBuilder)
{
containerBuilder.RegisterAssembly("NzbDrone.Common");
containerBuilder.RegisterAssembly("NzbDrone.Core");
containerBuilder.InitDatabase();
containerBuilder.RegisterType<EventAggregator>()
.As<IEventAggregator>().SingleInstance();
containerBuilder.RegisterModule<LogInjectionModule>();
}
private static void RegisterAssembly(this ContainerBuilder container, string assemblyName)
{
container.RegisterAssemblyTypes(assemblyName);
var assembly = Assembly.Load(assemblyName);
container.RegisterAssemblyTypes(assembly)
12 years ago
.Where(t => t.IsSubclassOf(typeof(IndexerBase)))
.As<IndexerBase>();
container.RegisterAssemblyTypes(assembly)
.Where(t => t.IsSubclassOf(typeof(IndexerSearchBase)))
.As<IndexerSearchBase>();
container.RegisterAssemblyTypes(assembly)
12 years ago
.Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase)))
.As<ExternalNotificationBase>();
}
private static void InitDatabase(this ContainerBuilder container)
{
12 years ago
logger.Info("Registering Database...");
var environmentProvider = new EnvironmentProvider();
var appDataPath = environmentProvider.GetAppDataPath();
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
container.Register(c => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase())).As<IDatabase>();
container.RegisterGeneric(typeof(BasicRepository<>)).As(typeof(IBasicRepository<>));
}
}
}