1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Core/ContainerExtensions.cs

69 lines
2.3 KiB
C#
Raw Normal View History

2013-03-24 05:16:00 +01:00
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;
2013-03-07 04:45:36 +01:00
using NzbDrone.Core.IndexerSearch;
2013-02-23 05:37:23 +01:00
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Instrumentation;
namespace NzbDrone.Core
{
public static class ContainerExtensions
{
2013-01-19 19:54:00 +01:00
private static readonly Logger logger = LogManager.GetLogger("ServiceRegistration");
public static void RegisterCoreServices(this ContainerBuilder containerBuilder)
{
2013-02-19 08:20:51 +01:00
containerBuilder.RegisterAssembly("NzbDrone.Common");
2013-02-19 02:57:08 +01:00
containerBuilder.RegisterAssembly("NzbDrone.Core");
containerBuilder.InitDatabase();
containerBuilder.RegisterType<EventAggregator>()
.As<IEventAggregator>().SingleInstance();
containerBuilder.RegisterModule<LogInjectionModule>();
}
2013-02-19 02:57:08 +01:00
private static void RegisterAssembly(this ContainerBuilder container, string assemblyName)
{
2013-01-19 20:42:06 +01:00
2013-02-19 02:57:08 +01:00
container.RegisterAssemblyTypes(assemblyName);
2013-02-19 02:57:08 +01:00
var assembly = Assembly.Load(assemblyName);
container.RegisterAssemblyTypes(assembly)
2013-01-19 19:54:00 +01:00
.Where(t => t.IsSubclassOf(typeof(IndexerBase)))
.As<IndexerBase>();
container.RegisterAssemblyTypes(assembly)
.Where(t => t.IsSubclassOf(typeof(IndexerSearchBase)))
.As<IndexerSearchBase>();
container.RegisterAssemblyTypes(assembly)
2013-01-19 19:54:00 +01:00
.Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase)))
.As<ExternalNotificationBase>();
}
2013-01-19 20:42:06 +01:00
private static void InitDatabase(this ContainerBuilder container)
{
2013-01-19 19:54:00 +01:00
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<>));
}
}
}