mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 03:52:33 +02:00
removed Autofac from update project.
This commit is contained in:
parent
55ece3d80d
commit
3f958109bb
@ -70,6 +70,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Omu.ValueInjecter">
|
||||
<HintPath>..\packages\ValueInjecter.2.3.3\lib\net35\Omu.ValueInjecter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@ -6,16 +6,15 @@
|
||||
using FluentValidation;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Api.REST;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Jobs.Implementations;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Model;
|
||||
|
||||
namespace NzbDrone.Api.Series
|
||||
{
|
||||
public class SeriesModule : NzbDroneApiModule
|
||||
public class SeriesModule : RestModule<SeriesResource>
|
||||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IJobController _jobProvider;
|
||||
|
@ -1,17 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NzbDrone.Api.QualityProfiles;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Api.REST;
|
||||
|
||||
namespace NzbDrone.Api.Series
|
||||
{
|
||||
public class SeriesResource
|
||||
public class SeriesResource : RestResource<SeriesResource>
|
||||
{
|
||||
public Int32 Id { get; set; }
|
||||
|
||||
//Todo: Sorters should be done completely on the client
|
||||
//Todo: Is there an easy way to keep IgnoreArticlesWhenSorting in sync between, Series, History, Missing?
|
||||
//Todo: We should get the entire QualityProfile instead of ID and Name separately
|
||||
|
@ -4,4 +4,5 @@
|
||||
<package id="FluentValidation" version="3.4.6.0" targetFramework="net40" />
|
||||
<package id="Nancy" version="0.16.1" targetFramework="net40" />
|
||||
<package id="NLog" version="2.0.1.2" targetFramework="net40" />
|
||||
<package id="ValueInjecter" version="2.3.3" targetFramework="net40" />
|
||||
</packages>
|
@ -14,19 +14,19 @@ public class ContainerFixture : TestBase
|
||||
[Test]
|
||||
public void should_be_able_to_resolve_event_handlers()
|
||||
{
|
||||
ContainerBuilder.BuildNzbDroneContainer().Resolve<IEnumerable<IHandle>>().Should().NotBeEmpty();
|
||||
MainAppContainerBuilder.BuildContainer().Resolve<IEnumerable<IHandle>>().Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_resolve_indexers()
|
||||
{
|
||||
ContainerBuilder.BuildNzbDroneContainer().Resolve<IEnumerable<IIndexerBase>>().Should().NotBeEmpty();
|
||||
MainAppContainerBuilder.BuildContainer().Resolve<IEnumerable<IIndexerBase>>().Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_resolve_downlodclients()
|
||||
{
|
||||
ContainerBuilder.BuildNzbDroneContainer().Resolve<IEnumerable<IDownloadClient>>().Should().NotBeEmpty();
|
||||
MainAppContainerBuilder.BuildContainer().Resolve<IEnumerable<IDownloadClient>>().Should().NotBeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
71
NzbDrone.Common/ContainerBuilderBase.cs
Normal file
71
NzbDrone.Common/ContainerBuilderBase.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public abstract class ContainerBuilderBase
|
||||
{
|
||||
protected TinyIoCContainer Container;
|
||||
private readonly List<Type> _loadedTypes;
|
||||
|
||||
protected ContainerBuilderBase(params string[] assemblies)
|
||||
{
|
||||
Container = new TinyIoCContainer();
|
||||
|
||||
_loadedTypes = new List<Type>();
|
||||
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
_loadedTypes.AddRange(Assembly.Load(assembly).GetTypes());
|
||||
}
|
||||
|
||||
AutoRegisterInterfaces();
|
||||
}
|
||||
|
||||
private void AutoRegisterInterfaces()
|
||||
{
|
||||
var interfaces = _loadedTypes.Where(t => t.IsInterface);
|
||||
|
||||
foreach (var contract in interfaces)
|
||||
{
|
||||
AutoRegisterImplementations(contract);
|
||||
}
|
||||
}
|
||||
|
||||
protected void AutoRegisterImplementations<TContract>()
|
||||
{
|
||||
AutoRegisterImplementations(typeof(TContract));
|
||||
}
|
||||
|
||||
private void AutoRegisterImplementations(Type contractType)
|
||||
{
|
||||
var implementations = GetImplementations(contractType).ToList();
|
||||
|
||||
if (implementations.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (implementations.Count == 1)
|
||||
{
|
||||
Container.Register(contractType, implementations.Single()).AsMultiInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
Container.RegisterMultiple(contractType, implementations).AsMultiInstance();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<Type> GetImplementations(Type contractType)
|
||||
{
|
||||
return _loadedTypes
|
||||
.Where(implementation =>
|
||||
contractType.IsAssignableFrom(implementation) &&
|
||||
!implementation.IsInterface &&
|
||||
!implementation.IsAbstract
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@ -84,6 +84,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ArchiveProvider.cs" />
|
||||
<Compile Include="ContainerBuilderBase.cs" />
|
||||
<Compile Include="EnsureThat\Ensure.cs" />
|
||||
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" />
|
||||
<Compile Include="EnsureThat\EnsureCollectionExtensions.cs" />
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="DotNetZip" version="1.9.1.8" />
|
||||
<package id="FluentMigrator" version="1.0.6.0" targetFramework="net40" />
|
||||
|
@ -69,7 +69,7 @@ private void InitDatabase()
|
||||
[SetUp]
|
||||
public void SmokeTestSetup()
|
||||
{
|
||||
Container = ContainerBuilder.BuildNzbDroneContainer();
|
||||
Container = MainAppContainerBuilder.BuildContainer();
|
||||
|
||||
InitDatabase();
|
||||
|
||||
|
@ -55,13 +55,6 @@
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Autofac, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Autofac.Configuration">
|
||||
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Exceptron.Client, Version=1.0.20.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Exceptron.Client.1.0.20\lib\net20\Exceptron.Client.dll</HintPath>
|
||||
@ -84,6 +77,7 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Providers\UpdateProvider.cs" />
|
||||
<Compile Include="UpdateContainerBuilder.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Autofac;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Update.Providers;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Update
|
||||
{
|
||||
@ -11,7 +11,7 @@ public class Program
|
||||
{
|
||||
private readonly UpdateProvider _updateProvider;
|
||||
private readonly ProcessProvider _processProvider;
|
||||
private static IContainer _container;
|
||||
private static TinyIoCContainer _container;
|
||||
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
@ -26,10 +26,8 @@ public static void Main(string[] args)
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Starting NzbDrone Update Client");
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterAssemblyTypes(typeof(UpdateProvider).Assembly).SingleInstance();
|
||||
builder.RegisterAssemblyTypes(typeof(RestProvider).Assembly).SingleInstance();
|
||||
_container = builder.Build();
|
||||
|
||||
_container = UpdateContainerBuilder.Build();
|
||||
|
||||
logger.Info("Updating NzbDrone to version {0}", _container.Resolve<EnvironmentProvider>().Version);
|
||||
_container.Resolve<Program>().Start(args);
|
||||
|
19
NzbDrone.Update/UpdateContainerBuilder.cs
Normal file
19
NzbDrone.Update/UpdateContainerBuilder.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using NzbDrone.Common;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone.Update
|
||||
{
|
||||
public class UpdateContainerBuilder : ContainerBuilderBase
|
||||
{
|
||||
public UpdateContainerBuilder()
|
||||
: base("NzbDrone.Update", "NzbDrone.Common")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static TinyIoCContainer Build()
|
||||
{
|
||||
return new UpdateContainerBuilder().Container;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Autofac" version="3.0.1" targetFramework="net40" />
|
||||
<package id="Exceptron.Client" version="1.0.20" targetFramework="net40" />
|
||||
<package id="Exceptron.Nlog" version="1.0.11" targetFramework="net40" />
|
||||
<package id="NLog" version="2.0.1.2" targetFramework="net40" />
|
||||
|
@ -2,6 +2,7 @@
|
||||
<FileVersion>1</FileVersion>
|
||||
<AutoEnableOnStartup>True</AutoEnableOnStartup>
|
||||
<AllowParallelTestExecution>true</AllowParallelTestExecution>
|
||||
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
|
||||
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
|
||||
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
|
||||
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>
|
||||
|
@ -41,7 +41,7 @@ public static void Main(string[] args)
|
||||
return;
|
||||
}
|
||||
|
||||
var container = ContainerBuilder.BuildNzbDroneContainer();
|
||||
var container = MainAppContainerBuilder.BuildContainer();
|
||||
|
||||
container.Resolve<Router>().Route(args);
|
||||
}
|
||||
|
@ -1,118 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using FluentMigrator.Runner;
|
||||
using NLog;
|
||||
using Nancy.Bootstrapper;
|
||||
using NzbDrone.Api;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Eventing;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
using NzbDrone.Core.ExternalNotification;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone
|
||||
{
|
||||
public static class ContainerBuilder
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilder");
|
||||
private static readonly List<Type> NzbDroneTypes;
|
||||
|
||||
static ContainerBuilder()
|
||||
{
|
||||
NzbDroneTypes = new List<Type>();
|
||||
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone").GetTypes());
|
||||
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Common").GetTypes());
|
||||
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Core").GetTypes());
|
||||
NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Api").GetTypes());
|
||||
}
|
||||
|
||||
public static TinyIoCContainer BuildNzbDroneContainer()
|
||||
{
|
||||
var container = new TinyIoCContainer();
|
||||
|
||||
container.AutoRegisterInterfaces();
|
||||
|
||||
container.AutoRegisterImplementations<ExternalNotificationBase>();
|
||||
|
||||
container.Register<IEventAggregator, EventAggregator>().AsSingleton();
|
||||
container.Register<INancyBootstrapper, NancyBootstrapper>().AsSingleton();
|
||||
container.Register<IAnnouncer, MigrationLogger>().AsSingleton();
|
||||
container.Register<Router>().AsSingleton();
|
||||
|
||||
container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>)).AsMultiInstance();
|
||||
container.Register(typeof(IBasicRepository<NameSpecification>), typeof(BasicRepository<NameSpecification>)).AsMultiInstance();
|
||||
|
||||
container.InitDatabase();
|
||||
|
||||
ReportingService.RestProvider = container.Resolve<RestProvider>();
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private static void InitDatabase(this TinyIoCContainer container)
|
||||
{
|
||||
Logger.Info("Registering Database...");
|
||||
|
||||
//TODO: move this to factory
|
||||
var environmentProvider = new EnvironmentProvider();
|
||||
var appDataPath = environmentProvider.GetAppDataPath();
|
||||
|
||||
if (!Directory.Exists(appDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(appDataPath);
|
||||
}
|
||||
|
||||
container.Register((c, p) => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
|
||||
}
|
||||
|
||||
private static void AutoRegisterInterfaces(this TinyIoCContainer container)
|
||||
{
|
||||
var interfaces = NzbDroneTypes.Where(t => t.IsInterface);
|
||||
|
||||
foreach (var contract in interfaces)
|
||||
{
|
||||
container.AutoRegisterImplementations(contract);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void AutoRegisterImplementations<TContract>(this TinyIoCContainer container)
|
||||
{
|
||||
container.AutoRegisterImplementations(typeof(TContract));
|
||||
}
|
||||
|
||||
private static void AutoRegisterImplementations(this TinyIoCContainer container, Type contractType)
|
||||
{
|
||||
var implementations = GetImplementations(contractType).ToList();
|
||||
|
||||
if (implementations.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (implementations.Count == 1)
|
||||
{
|
||||
container.Register(contractType, implementations.Single()).AsMultiInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
container.RegisterMultiple(contractType, implementations).AsMultiInstance();
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<Type> GetImplementations(Type contractType)
|
||||
{
|
||||
return NzbDroneTypes
|
||||
.Where(implementation =>
|
||||
contractType.IsAssignableFrom(implementation) &&
|
||||
!implementation.IsInterface &&
|
||||
!implementation.IsAbstract
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
61
NzbDrone/MainAppContainerBuilder.cs
Normal file
61
NzbDrone/MainAppContainerBuilder.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System.IO;
|
||||
using FluentMigrator.Runner;
|
||||
using NLog;
|
||||
using Nancy.Bootstrapper;
|
||||
using NzbDrone.Api;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Eventing;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
using NzbDrone.Core.ExternalNotification;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using TinyIoC;
|
||||
|
||||
namespace NzbDrone
|
||||
{
|
||||
public class MainAppContainerBuilder : ContainerBuilderBase
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilderBase");
|
||||
|
||||
public static TinyIoCContainer BuildContainer()
|
||||
{
|
||||
return new MainAppContainerBuilder().Container;
|
||||
}
|
||||
|
||||
|
||||
private MainAppContainerBuilder()
|
||||
: base("NzbDrone", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api")
|
||||
{
|
||||
AutoRegisterImplementations<ExternalNotificationBase>();
|
||||
|
||||
Container.Register<IEventAggregator, EventAggregator>().AsSingleton();
|
||||
Container.Register<INancyBootstrapper, NancyBootstrapper>().AsSingleton();
|
||||
Container.Register<IAnnouncer, MigrationLogger>().AsSingleton();
|
||||
Container.Register<Router>().AsSingleton();
|
||||
|
||||
Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>)).AsMultiInstance();
|
||||
Container.Register(typeof(IBasicRepository<NameSpecification>), typeof(BasicRepository<NameSpecification>)).AsMultiInstance();
|
||||
|
||||
InitDatabase();
|
||||
|
||||
ReportingService.RestProvider = Container.Resolve<RestProvider>();
|
||||
}
|
||||
|
||||
private void InitDatabase()
|
||||
{
|
||||
Logger.Info("Registering Database...");
|
||||
|
||||
//TODO: move this to factory
|
||||
var environmentProvider = new EnvironmentProvider();
|
||||
var appDataPath = environmentProvider.GetAppDataPath();
|
||||
|
||||
if (!Directory.Exists(appDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(appDataPath);
|
||||
}
|
||||
|
||||
Container.Register((c, p) => c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase()));
|
||||
}
|
||||
}
|
||||
}
|
@ -118,7 +118,7 @@
|
||||
<Compile Include="ApplicationServer.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContainerBuilder.cs" />
|
||||
<Compile Include="MainAppContainerBuilder.cs" />
|
||||
<Compile Include="ApplicationMode.cs" />
|
||||
<Compile Include="AppMain.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user