2013-01-19 05:46:43 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Core;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
|
|
|
|
using NzbDrone.Core.Providers.ExternalNotification;
|
|
|
|
|
using NzbDrone.Core.Providers.Indexer;
|
|
|
|
|
using NzbDrone.Core.Providers.Metadata;
|
|
|
|
|
using NzbDrone.Core.Providers.Search;
|
|
|
|
|
using PetaPoco;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core
|
|
|
|
|
{
|
|
|
|
|
public static class ContainerExtentions
|
|
|
|
|
{
|
|
|
|
|
|
2013-01-19 19:54:00 +01:00
|
|
|
|
private static readonly Logger logger = LogManager.GetLogger("ServiceRegistration");
|
2013-01-19 05:46:43 +01:00
|
|
|
|
|
2013-01-20 01:19:27 +01:00
|
|
|
|
public static void RegisterCoreServices(this ContainerBuilder containerBuilder)
|
2013-01-19 05:46:43 +01:00
|
|
|
|
{
|
2013-02-19 02:57:08 +01:00
|
|
|
|
containerBuilder.RegisterAssembly("NzbDrone.Core");
|
2013-01-19 05:46:43 +01:00
|
|
|
|
|
2013-01-20 01:19:27 +01:00
|
|
|
|
containerBuilder.InitDatabase();
|
|
|
|
|
|
|
|
|
|
containerBuilder.RegisterModule<LogInjectionModule>();
|
2013-01-19 05:46:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-19 02:57:08 +01:00
|
|
|
|
private static void RegisterAssembly(this ContainerBuilder container, string assemblyName)
|
2013-01-19 05:46:43 +01:00
|
|
|
|
{
|
2013-01-19 20:42:06 +01:00
|
|
|
|
|
2013-02-19 02:57:08 +01:00
|
|
|
|
container.RegisterAssemblyTypes(assemblyName);
|
2013-01-19 05:46:43 +01:00
|
|
|
|
|
2013-02-19 02:57:08 +01:00
|
|
|
|
var assembly = Assembly.Load(assemblyName);
|
2013-01-19 05:46:43 +01:00
|
|
|
|
|
|
|
|
|
container.RegisterAssemblyTypes(assembly)
|
2013-01-19 19:54:00 +01:00
|
|
|
|
.Where(t => t.IsSubclassOf(typeof(IndexerBase)))
|
2013-01-19 05:46:43 +01:00
|
|
|
|
.As<IndexerBase>().SingleInstance();
|
|
|
|
|
|
|
|
|
|
container.RegisterAssemblyTypes(assembly)
|
2013-01-19 19:54:00 +01:00
|
|
|
|
.Where(t => t.IsSubclassOf(typeof(SearchBase)))
|
2013-01-19 05:46:43 +01:00
|
|
|
|
.As<SearchBase>().SingleInstance();
|
|
|
|
|
|
|
|
|
|
container.RegisterAssemblyTypes(assembly)
|
2013-01-19 19:54:00 +01:00
|
|
|
|
.Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase)))
|
2013-01-19 05:46:43 +01:00
|
|
|
|
.As<ExternalNotificationBase>().SingleInstance();
|
|
|
|
|
|
|
|
|
|
container.RegisterAssemblyTypes(assembly)
|
2013-01-19 19:54:00 +01:00
|
|
|
|
.Where(t => t.IsSubclassOf(typeof(MetadataBase)))
|
2013-01-19 05:46:43 +01:00
|
|
|
|
.As<MetadataBase>().SingleInstance();
|
|
|
|
|
}
|
2013-01-19 20:42:06 +01:00
|
|
|
|
|
2013-01-19 05:46:43 +01:00
|
|
|
|
private static void InitDatabase(this ContainerBuilder container)
|
|
|
|
|
{
|
2013-01-19 19:54:00 +01:00
|
|
|
|
logger.Info("Registering Database...");
|
2013-01-19 05:46:43 +01:00
|
|
|
|
|
|
|
|
|
var appDataPath = new EnvironmentProvider().GetAppDataPath();
|
|
|
|
|
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
|
|
|
|
|
|
2013-01-19 20:42:06 +01:00
|
|
|
|
container.Register(c => c.Resolve<ConnectionFactory>().GetMainPetaPocoDb())
|
2013-01-19 05:46:43 +01:00
|
|
|
|
.As<IDatabase>();
|
|
|
|
|
|
2013-01-19 20:42:06 +01:00
|
|
|
|
container.Register(c => c.Resolve<ConnectionFactory>().GetLogPetaPocoDb(false))
|
2013-01-19 05:46:43 +01:00
|
|
|
|
.SingleInstance()
|
|
|
|
|
.Named<IDatabase>("DatabaseTarget");
|
|
|
|
|
|
2013-01-19 20:42:06 +01:00
|
|
|
|
container.Register(c => c.Resolve<ConnectionFactory>().GetLogPetaPocoDb())
|
2013-01-19 05:46:43 +01:00
|
|
|
|
.Named<IDatabase>("LogProvider");
|
|
|
|
|
|
2013-02-04 02:27:34 +01:00
|
|
|
|
container.Register(c =>
|
|
|
|
|
{
|
2013-02-17 05:59:35 +01:00
|
|
|
|
return c.Resolve<IObjectDbFactory>().Create();
|
2013-02-17 05:33:56 +01:00
|
|
|
|
}).As<IObjectDatabase>().SingleInstance();
|
2013-02-04 02:27:34 +01:00
|
|
|
|
|
2013-02-17 06:09:35 +01:00
|
|
|
|
container.RegisterGeneric(typeof(BasicRepository<>)).As(typeof(IBasicRepository<>));
|
|
|
|
|
|
2013-01-19 05:46:43 +01:00
|
|
|
|
container.RegisterType<DatabaseTarget>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("DatabaseTarget"));
|
|
|
|
|
container.RegisterType<LogProvider>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("LogProvider"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|