1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/ContainerExtensions.cs

70 lines
2.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Autofac;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.ExternalNotification;
2013-02-23 07:37:23 +03:00
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Providers.Search;
namespace NzbDrone.Core
{
public static class ContainerExtensions
{
2013-01-19 21:54:00 +03:00
private static readonly Logger logger = LogManager.GetLogger("ServiceRegistration");
public static void RegisterCoreServices(this ContainerBuilder containerBuilder)
{
2013-02-19 10:20:51 +03:00
containerBuilder.RegisterAssembly("NzbDrone.Common");
2013-02-19 04:57:08 +03:00
containerBuilder.RegisterAssembly("NzbDrone.Core");
containerBuilder.InitDatabase();
containerBuilder.RegisterModule<LogInjectionModule>();
}
2013-02-19 04:57:08 +03:00
private static void RegisterAssembly(this ContainerBuilder container, string assemblyName)
{
2013-01-19 22:42:06 +03:00
2013-02-19 04:57:08 +03:00
container.RegisterAssemblyTypes(assemblyName);
2013-02-19 04:57:08 +03:00
var assembly = Assembly.Load(assemblyName);
container.RegisterAssemblyTypes(assembly)
2013-01-19 21:54:00 +03:00
.Where(t => t.IsSubclassOf(typeof(IndexerBase)))
.As<IndexerBase>().SingleInstance();
container.RegisterAssemblyTypes(assembly)
2013-01-19 21:54:00 +03:00
.Where(t => t.IsSubclassOf(typeof(SearchBase)))
.As<SearchBase>().SingleInstance();
container.RegisterAssemblyTypes(assembly)
2013-01-19 21:54:00 +03:00
.Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase)))
.As<ExternalNotificationBase>().SingleInstance();
}
2013-01-19 22:42:06 +03:00
private static void InitDatabase(this ContainerBuilder container)
{
2013-01-19 21:54:00 +03:00
logger.Info("Registering Database...");
var appDataPath = new EnvironmentProvider().GetAppDataPath();
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
2013-02-04 04:27:34 +03:00
container.Register(c =>
{
return c.Resolve<IObjectDbFactory>().Create();
}).As<IObjectDatabase>().SingleInstance();
2013-02-04 04:27:34 +03:00
container.RegisterGeneric(typeof(BasicRepository<>)).As(typeof(IBasicRepository<>));
}
}
}