replaced autofac with TinyIoC

pull/4/head
Keivan Beigi 11 years ago
parent bcc20fc8a1
commit aacc53d882

@ -20,7 +20,8 @@
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile />
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>

@ -1,16 +0,0 @@
using System.Linq;
using Autofac;
using Nancy.Bootstrapper;
using NzbDrone.Common;
namespace NzbDrone.Api
{
public static class ApiContainerExtensions
{
public static void RegisterApiServices(this ContainerBuilder containerBuilder)
{
containerBuilder.RegisterAssemblyTypes("NzbDrone.Api");
containerBuilder.RegisterType<NancyBootstrapper>().As<INancyBootstrapper>();
}
}
}

@ -1,14 +0,0 @@
using System.IO;
using System.Linq;
using Nancy;
namespace NzbDrone.Api.Extensions
{
public class RootPathProvider : IRootPathProvider
{
public string GetRootPath()
{
return Directory.GetCurrentDirectory();
}
}
}

@ -1,54 +1,48 @@
using System;
using System.Collections.Generic;
using Autofac;
using NLog;
using Nancy;
using Nancy.Bootstrapper;
using Nancy.Bootstrappers.Autofac;
using Nancy.Conventions;
using Nancy.Diagnostics;
using NzbDrone.Api.ErrorManagement;
using NzbDrone.Api.Extensions;
using NzbDrone.Api.Frontend;
using NzbDrone.Common;
using NzbDrone.Core;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Lifecycle;
using SignalR;
using TinyIoC;
using ErrorPipeline = NzbDrone.Api.ErrorManagement.ErrorPipeline;
namespace NzbDrone.Api
{
public class NancyBootstrapper : AutofacNancyBootstrapper
public class TinyNancyBootstrapper : TinyIoCNancyBootstrapper
{
private readonly TinyIoCContainer _tinyIoCContainer;
private readonly Logger _logger;
public NancyBootstrapper()
public TinyNancyBootstrapper(TinyIoCContainer tinyIoCContainer)
{
_tinyIoCContainer = tinyIoCContainer;
_logger = LogManager.GetCurrentClassLogger();
}
protected override Nancy.IRootPathProvider RootPathProvider
{
get
{
return new RootPathProvider();
}
}
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
_logger.Info("Starting NzbDrone API");
AutomapperBootstraper.InitializeAutomapper();
SignalRBootstraper.InitializeAutomapper(container);
RegisterReporting(container);
KickoffInitilizables(container);
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<ErrorPipeline>().HandleException);
}
private void KickoffInitilizables(ILifetimeScope container)
private void RegisterReporting(TinyIoCContainer container)
{
EnvironmentProvider.UGuid = container.Resolve<ConfigService>().UGuid;
ReportingService.RestProvider = container.Resolve<RestProvider>();
}
private void KickoffInitilizables(TinyIoCContainer container)
{
var initilizables = container.Resolve<IEnumerable<IInitializable>>();
@ -67,23 +61,10 @@ namespace NzbDrone.Api
}
}
private void RegisterReporting(ILifetimeScope container)
{
EnvironmentProvider.UGuid = container.Resolve<ConfigService>().UGuid;
ReportingService.RestProvider = container.Resolve<RestProvider>();
}
protected override ILifetimeScope GetApplicationContainer()
protected override TinyIoCContainer GetApplicationContainer()
{
_logger.Debug("Initializing Service Container");
var builder = new ContainerBuilder();
builder.RegisterCoreServices();
builder.RegisterApiServices();
var container = builder.Build();
return container;
return _tinyIoCContainer;
}
protected override NancyInternalConfiguration InternalConfiguration
@ -110,15 +91,5 @@ namespace NzbDrone.Api
var processors = ApplicationContainer.Resolve<IProcessStaticResource>();
Conventions.StaticContentsConventions.Add(processors.ProcessStaticResourceRequest);
}
}
public static class SignalRBootstraper
{
public static void InitializeAutomapper(ILifetimeScope container)
{
GlobalHost.DependencyResolver = new AutofacSignalrDependencyResolver(container.BeginLifetimeScope("SignalR"));
}
}
}

@ -13,6 +13,8 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -53,10 +55,6 @@
<StartupObject />
</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="AutoMapper, Version=2.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\AutoMapper.2.2.1\lib\net40\AutoMapper.dll</HintPath>
@ -68,10 +66,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="Nancy.Bootstrappers.Autofac, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.Bootstrappers.Autofac.0.16.1\lib\net40\Nancy.Bootstrappers.Autofac.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
@ -94,7 +88,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AutomapperBootstraper.cs" />
<Compile Include="ApiContainerExtensions.cs" />
<Compile Include="Calendar\CalendarModule.cs" />
<Compile Include="Calendar\CalendarResource.cs" />
<Compile Include="Directories\DirectoryModule.cs" />
@ -111,7 +104,6 @@
<Compile Include="Resolvers\NextAiringResolver.cs" />
<Compile Include="Resolvers\NullableDatetimeToString.cs" />
<Compile Include="RootFolders\RootFolderModule.cs" />
<Compile Include="Extensions\RootPathProvider.cs" />
<Compile Include="Seasons\SeasonModule.cs" />
<Compile Include="Series\SeriesResource.cs" />
<Compile Include="Series\SeriesModule.cs" />
@ -133,6 +125,8 @@
<Compile Include="Resolvers\QualitiesToAllowedResolver.cs" />
<Compile Include="Resolvers\QualityTypesToIntResolver.cs" />
<Compile Include="Settings\SettingsModule.cs" />
<Compile Include="TinyIoCDependencyResolver.cs" />
<Compile Include="TinyIoCNancyBootstrapper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SignalR;
using TinyIoC;
namespace NzbDrone.Api
{
public class TinyIoCDependencyResolver : DefaultDependencyResolver
{
private readonly TinyIoCContainer _container;
public TinyIoCDependencyResolver(TinyIoCContainer container)
{
_container = container;
}
public override object GetService(Type serviceType)
{
if (_container.CanResolve(serviceType))
{
return _container.Resolve(serviceType);
}
return base.GetService(serviceType);
}
public override IEnumerable<object> GetServices(Type serviceType)
{
IEnumerable<object> services = new object[] { };
if (_container.CanResolve(serviceType))
{
services = _container.ResolveAll(serviceType);
}
return services.Concat(base.GetServices(serviceType));
}
}
}

@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Nancy;
using Nancy.Bootstrapper;
using Nancy.Diagnostics;
using TinyIoC;
namespace NzbDrone.Api
{
public abstract class TinyIoCNancyBootstrapper : NancyBootstrapperWithRequestContainerBase<TinyIoCContainer>
{
/// <summary>
/// Resolve INancyEngine
/// </summary>
/// <returns>INancyEngine implementation</returns>
protected override sealed INancyEngine GetEngineInternal()
{
return this.ApplicationContainer.Resolve<INancyEngine>();
}
/// <summary>
/// Get the moduleKey generator
/// </summary>
/// <returns>IModuleKeyGenerator instance</returns>
protected override sealed IModuleKeyGenerator GetModuleKeyGenerator()
{
return this.ApplicationContainer.Resolve<IModuleKeyGenerator>();
}
/// <summary>
/// Create a default, unconfigured, container
/// </summary>
/// <returns>Container instance</returns>
protected override TinyIoCContainer GetApplicationContainer()
{
return new TinyIoCContainer();
}
/// <summary>
/// Register the bootstrapper's implemented types into the container.
/// This is necessary so a user can pass in a populated container but not have
/// to take the responsibility of registering things like INancyModuleCatalog manually.
/// </summary>
/// <param name="applicationContainer">Application container to register into</param>
protected override sealed void RegisterBootstrapperTypes(TinyIoCContainer applicationContainer)
{
applicationContainer.Register<INancyModuleCatalog>(this);
}
/// <summary>
/// Register the default implementations of internally used types into the container as singletons
/// </summary>
/// <param name="container">Container to register into</param>
/// <param name="typeRegistrations">Type registrations to register</param>
protected override sealed void RegisterTypes(TinyIoCContainer container, IEnumerable<TypeRegistration> typeRegistrations)
{
foreach (var typeRegistration in typeRegistrations)
{
container.Register(typeRegistration.RegistrationType, typeRegistration.ImplementationType).AsSingleton();
}
}
/// <summary>
/// Register the various collections into the container as singletons to later be resolved
/// by IEnumerable{Type} constructor dependencies.
/// </summary>
/// <param name="container">Container to register into</param>
/// <param name="collectionTypeRegistrationsn">Collection type registrations to register</param>
protected override sealed void RegisterCollectionTypes(TinyIoCContainer container, IEnumerable<CollectionTypeRegistration> collectionTypeRegistrationsn)
{
foreach (var collectionTypeRegistration in collectionTypeRegistrationsn)
{
container.RegisterMultiple(collectionTypeRegistration.RegistrationType, collectionTypeRegistration.ImplementationTypes.Distinct());
}
}
/// <summary>
/// Register the given module types into the container
/// </summary>
/// <param name="container">Container to register into</param>
/// <param name="moduleRegistrationTypes">NancyModule types</param>
protected override sealed void RegisterRequestContainerModules(TinyIoCContainer container, IEnumerable<ModuleRegistration> moduleRegistrationTypes)
{
foreach (var moduleRegistrationType in moduleRegistrationTypes)
{
container.Register(
typeof(INancyModule),
moduleRegistrationType.ModuleType,
moduleRegistrationType.ModuleKey).
AsSingleton();
}
}
/// <summary>
/// Register the given instances into the container
/// </summary>
/// <param name="container">Container to register into</param>
/// <param name="instanceRegistrations">Instance registration types</param>
protected override void RegisterInstances(TinyIoCContainer container, IEnumerable<InstanceRegistration> instanceRegistrations)
{
foreach (var instanceRegistration in instanceRegistrations)
{
container.Register(
instanceRegistration.RegistrationType,
instanceRegistration.Implementation);
}
}
/// <summary>
/// Creates a per request child/nested container
/// </summary>
/// <returns>Request container instance</returns>
protected override sealed TinyIoCContainer CreateRequestContainer()
{
return this.ApplicationContainer.GetChildContainer();
}
/// <summary>
/// Gets the diagnostics for intialisation
/// </summary>
/// <returns>IDagnostics implementation</returns>
protected override IDiagnostics GetDiagnostics()
{
return this.ApplicationContainer.Resolve<IDiagnostics>();
}
/// <summary>
/// Gets all registered startup tasks
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IApplicationStartup"/> instances. </returns>
protected override IEnumerable<IApplicationStartup> GetApplicationStartupTasks()
{
return this.ApplicationContainer.ResolveAll<IApplicationStartup>(false);
}
/// <summary>
/// Gets all registered application registration tasks
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IApplicationRegistrations"/> instances.</returns>
protected override IEnumerable<IApplicationRegistrations> GetApplicationRegistrationTasks()
{
return this.ApplicationContainer.ResolveAll<IApplicationRegistrations>(false);
}
/// <summary>
/// Retrieve all module instances from the container
/// </summary>
/// <param name="container">Container to use</param>
/// <returns>Collection of NancyModule instances</returns>
protected override sealed IEnumerable<INancyModule> GetAllModules(TinyIoCContainer container)
{
var nancyModules = container.ResolveAll<INancyModule>(false);
return nancyModules;
}
/// <summary>
/// Retreive a specific module instance from the container by its key
/// </summary>
/// <param name="container">Container to use</param>
/// <param name="moduleKey">Module key of the module</param>
/// <returns>NancyModule instance</returns>
protected override sealed INancyModule GetModuleByKey(TinyIoCContainer container, string moduleKey)
{
return container.Resolve<INancyModule>(moduleKey);
}
/// <summary>
/// Executes auto registation with the given container.
/// </summary>
/// <param name="container">Container instance</param>
private static void AutoRegister(TinyIoCContainer container, IEnumerable<Func<Assembly, bool>> ignoredAssemblies)
{
var assembly = typeof(NancyEngine).Assembly;
var whitelist = new Type[] { };
container.AutoRegister(AppDomain.CurrentDomain.GetAssemblies().Where(a => !ignoredAssemblies.Any(ia => ia(a))), t => t.Assembly != assembly || whitelist.Any(wt => wt == t));
}
}
}

@ -1,10 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="AutoMapper" version="2.2.1" targetFramework="net40" />
<package id="FluentValidation" version="3.4.6.0" targetFramework="net40" />
<package id="Nancy" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Bootstrappers.Autofac" version="0.16.1" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" targetFramework="net40" />
<package id="SignalR.Hosting.Common" version="0.5.3" targetFramework="net40" />

@ -53,10 +53,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="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>

@ -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="FluentAssertions" version="2.0.1" targetFramework="net40" />

@ -53,14 +53,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, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions, Version=2.0.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\FluentAssertions.2.0.1\lib\net40\FluentAssertions.dll</HintPath>

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="FluentAssertions" version="2.0.1" targetFramework="net40" />
<package id="Moq" version="4.0.10827" />
<package id="NLog" version="2.0.0.2000" />

@ -1,31 +0,0 @@
using System;
using System.Linq;
using System.Reflection;
using Autofac;
namespace NzbDrone.Common
{
public static class CommonContainerExtensions
{
public static void RegisterCommonServices(this ContainerBuilder containerBuilder)
{
containerBuilder.RegisterAssemblyTypes("NzbDrone.Common");
}
public static void RegisterAssemblyTypes(this ContainerBuilder containerBuilder, string assemblyName)
{
var apiAssembly = Assembly.Load(assemblyName);
if (apiAssembly == null)
{
throw new ApplicationException("Couldn't load assembly " + assemblyName);
}
containerBuilder.RegisterAssemblyTypes(apiAssembly)
.AsImplementedInterfaces();
containerBuilder.RegisterAssemblyTypes(apiAssembly)
.AsSelf();
}
}
}

@ -14,6 +14,8 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -53,10 +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="Ionic.Zip">
<HintPath>..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
</Reference>
@ -84,7 +82,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ArchiveProvider.cs" />
<Compile Include="CommonContainerExtentions.cs" />
<Compile Include="EnsureThat\Ensure.cs" />
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" />
<Compile Include="EnsureThat\EnsureCollectionExtensions.cs" />
@ -111,6 +108,7 @@
<Compile Include="Eventing\IHandle.cs" />
<Compile Include="HostController.cs" />
<Compile Include="Instrumentation\VersionLayoutRenderer.cs" />
<Compile Include="ReflectionExtentions.cs" />
<Compile Include="StringExtention.cs" />
<Compile Include="HttpProvider.cs" />
<Compile Include="ConfigFileProvider.cs" />
@ -133,6 +131,7 @@
<SubType>Form</SubType>
</Compile>
<Compile Include="SysTray\SysTrayProvider.cs" />
<Compile Include="TinyIoC.cs" />
<Compile Include="TryParseExtension.cs" />
<Compile Include="UdpProvider.cs" />
</ItemGroup>

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace NzbDrone.Common
{
public static class ReflectionExtensions
{
public static IEnumerable<Type> GetInterfaces(this Assembly assembly)
{
return assembly.GetTypes().Where(c => c.IsInterface);
}
public static IEnumerable<Type> GetImplementations(this Assembly assembly, Type contractType)
{
return assembly.GetTypes()
.Where(implementation =>
contractType.IsAssignableFrom(implementation) &&
!implementation.IsInterface &&
!implementation.IsAbstract
);
}
}
}

File diff suppressed because it is too large Load Diff

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="DotNetZip" version="1.9.1.8" targetFramework="net40" />
<package id="Nancy" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />

@ -12,7 +12,8 @@
<AssemblyName>NzbDrone.Console</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>

@ -56,14 +56,6 @@
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</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, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="AutoMoq">
<HintPath>..\packages\AutoMoq.1.6.1\lib\AutoMoq.dll</HintPath>
</Reference>

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="AutoMoq" version="1.6.1" targetFramework="net40" />
<package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
<package id="FluentAssertions" version="2.0.1" targetFramework="net40" />

@ -1,3 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<configuration>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

@ -1,94 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac;
using Autofac.Builder;
using Autofac.Core;
using SignalR;
namespace NzbDrone.Core
{
public class AutofacSignalrDependencyResolver : DefaultDependencyResolver, IDependencyResolver, IRegistrationSource
{
private ILifetimeScope LifetimeScope { get; set; }
public AutofacSignalrDependencyResolver(ILifetimeScope lifetimeScope)
{
LifetimeScope = lifetimeScope;
var currentRegistrationSource =
LifetimeScope.ComponentRegistry.Sources.FirstOrDefault(s => s.GetType() == GetType());
if (currentRegistrationSource != null)
{
((AutofacSignalrDependencyResolver)currentRegistrationSource).LifetimeScope = lifetimeScope;
}
else
{
LifetimeScope.ComponentRegistry.AddRegistrationSource(this);
}
}
public AutofacSignalrDependencyResolver()
{
}
public override object GetService(Type serviceType)
{
object result;
if (LifetimeScope == null)
{
return base.GetService(serviceType);
}
if (LifetimeScope.TryResolve(serviceType, out result))
{
return result;
}
return null;
}
public override IEnumerable<object> GetServices(Type serviceType)
{
object result;
if (LifetimeScope == null)
{
return base.GetServices(serviceType);
}
if (LifetimeScope.TryResolve(typeof(IEnumerable<>).MakeGenericType(serviceType), out result))
{
return (IEnumerable<object>)result;
}
return Enumerable.Empty<object>();
}
public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Func<Service, IEnumerable<IComponentRegistration>> registrationAccessor)
{
var typedService = service as TypedService;
if (typedService != null)
{
var instances = base.GetServices(typedService.ServiceType);
if (instances != null)
{
return instances
.Select(i => RegistrationBuilder.ForDelegate(i.GetType(), (c, p) => i).As(typedService.ServiceType)
.InstancePerLifetimeScope()
.PreserveExistingDefaults()
.CreateRegistration());
}
}
return Enumerable.Empty<IComponentRegistration>();
}
bool IRegistrationSource.IsAdapterForIndividualComponents
{
get { return false; }
}
}
}

@ -1,69 +0,0 @@
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
{
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)
.Where(t => t.IsSubclassOf(typeof(IndexerBase)))
.As<IndexerBase>();
container.RegisterAssemblyTypes(assembly)
.Where(t => t.IsSubclassOf(typeof(IndexerSearchBase)))
.As<IndexerSearchBase>();
container.RegisterAssemblyTypes(assembly)
.Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase)))
.As<ExternalNotificationBase>();
}
private static void InitDatabase(this ContainerBuilder container)
{
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<>));
}
}
}

@ -10,6 +10,8 @@ using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Model;
using NzbDrone.Core.Tv;
using RestSharp.Contrib;
using HttpUtility = System.Web.HttpUtility;
namespace NzbDrone.Core.Download.Clients.Sabnzbd
{

@ -1,29 +0,0 @@
using System;
using System.Linq;
using Autofac;
using Autofac.Core;
using NLog;
namespace NzbDrone.Core.Instrumentation
{
public class LogInjectionModule : Module
{
protected override void AttachToComponentRegistration(IComponentRegistry registry, IComponentRegistration registration)
{
registration.Preparing += OnComponentPreparing;
}
static void OnComponentPreparing(object sender, PreparingEventArgs e)
{
e.Parameters = e.Parameters.Union(new[]
{
new ResolvedParameter((p, i) => p.ParameterType == typeof(Logger), (p,i)=> GetLogger(p.Member.DeclaringType))
});
}
private static object GetLogger(Type type)
{
return LogManager.GetLogger(type.Name);
}
}
}

@ -123,10 +123,6 @@
<StartupObject />
</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="FluentMigrator">
<HintPath>..\packages\FluentMigrator.1.0.6.0\lib\40\FluentMigrator.dll</HintPath>
</Reference>
@ -189,7 +185,6 @@
<Compile Include="Configuration\ConfigRepository.cs" />
<Compile Include="Configuration\IConfigService.cs" />
<Compile Include="Constants.cs" />
<Compile Include="ContainerExtensions.cs" />
<Compile Include="DataAugmentation\DailySeries\DailySeriesDataProxy.cs" />
<Compile Include="DataAugmentation\DailySeries\DailySeriesService.cs" />
<Compile Include="DataAugmentation\Scene\SceneMapping.cs" />
@ -249,7 +244,6 @@
<Compile Include="IndexerSearch\IndexerSearchBase.cs" />
<Compile Include="Indexers\IndexerRepository.cs" />
<Compile Include="Indexers\NewznabRepository.cs" />
<Compile Include="Instrumentation\LogInjectionModule.cs" />
<Compile Include="Instrumentation\LogRepository.cs" />
<Compile Include="Jobs\IJob.cs" />
<Compile Include="Jobs\Implementations\BacklogSearchJob.cs" />
@ -355,7 +349,6 @@
<Compile Include="Model\Xem\XemResult.cs" />
<Compile Include="Model\Xem\XemSceneTvdbMapping.cs" />
<Compile Include="Model\Xem\XemValues.cs" />
<Compile Include="AutofacSignalrDependencyResolver.cs" />
<Compile Include="MediaCover\MediaCoverService.cs" />
<Compile Include="Download\Clients\Nzbget\NzbgetProvider.cs" />
<Compile Include="Providers\MediaInfoProvider.cs" />

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Script.Serialization;
using System.Xml.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -67,7 +66,7 @@ namespace NzbDrone.Core.Providers
var activePlayers = GetActivePlayersDharma(host, username, password);
//If video is currently playing, then skip update
if(activePlayers["video"])
if (activePlayers["video"])
{
Logger.Debug("Video is currently playing, skipping library update");
continue;
@ -87,7 +86,7 @@ namespace NzbDrone.Core.Providers
var activePlayers = GetActivePlayersEden(host, username, password);
//If video is currently playing, then skip update
if(activePlayers.Any(a => a.Type.Equals("video")))
if (activePlayers.Any(a => a.Type.Equals("video")))
{
Logger.Debug("Video is currently playing, skipping library update");
continue;
@ -201,7 +200,7 @@ namespace NzbDrone.Core.Providers
Logger.Trace(" from response");
var result = JsonConvert.DeserializeObject<XbmcJsonResult<String>>(response);
if(!result.Result.Equals("OK", StringComparison.InvariantCultureIgnoreCase))
if (!result.Result.Equals("OK", StringComparison.InvariantCultureIgnoreCase))
return false;
}
@ -242,7 +241,7 @@ namespace NzbDrone.Core.Providers
Logger.DebugException(ex.Message, ex);
return false;
}
return true;
}
@ -329,7 +328,7 @@ namespace NzbDrone.Core.Providers
if (versionObject.Value.Type == JTokenType.Integer)
return new XbmcVersion((int)versionObject.Value);
if(versionObject.Value.Type == JTokenType.Object)
if (versionObject.Value.Type == JTokenType.Object)
return JsonConvert.DeserializeObject<XbmcVersion>(versionObject.Value.ToString());
throw new InvalidCastException("Unknown Version structure!: " + versionObject);
@ -430,8 +429,7 @@ namespace NzbDrone.Core.Providers
if (response.StartsWith("{\"error\""))
{
var serializer = new JavaScriptSerializer();
var error = serializer.Deserialize<ErrorResult>(response);
var error = JsonConvert.DeserializeObject<ErrorResult>(response);
var code = error.Error["code"];
var message = error.Error["message"];

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="DotNetZip" version="1.9.1.8" />
<package id="FluentMigrator" version="1.0.6.0" targetFramework="net40" />
<package id="Growl" version="0.6" />

@ -59,6 +59,9 @@
<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>

@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.Reflection;
using Autofac;
using NLog;
namespace NzbDrone
@ -42,8 +41,7 @@ namespace NzbDrone
return;
}
NzbDroneBootstrapper.Container.Resolve<Router>().Route(args);
ContainerBuilder.Instance.Resolve<Router>().Route(args);
}
catch (Exception e)
{

@ -30,11 +30,6 @@ namespace NzbDrone
_securityProvider = securityProvider;
}
public ApplicationServer()
{
}
protected override void OnStart(string[] args)
{
Start();

@ -0,0 +1,100 @@
using System;
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.IndexerSearch;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.RootFolders;
using TinyIoC;
namespace NzbDrone
{
public static class ContainerBuilder
{
private static readonly Logger logger = LogManager.GetLogger("ContainerBuilder");
public static TinyIoCContainer Instance { get; private set; }
static ContainerBuilder()
{
var container = new TinyIoCContainer();
container.AutoRegisterInterfaces("NzbDrone");
container.AutoRegisterInterfaces("NzbDrone.Common");
container.AutoRegisterInterfaces("NzbDrone.Core");
container.AutoRegisterInterfaces("NzbDrone.Api");
container.AutoRegisterImplementations<IndexerBase>();
container.AutoRegisterImplementations<IndexerSearchBase>();
container.AutoRegisterImplementations<ExternalNotificationBase>();
container.Register<IEventAggregator, EventAggregator>().AsSingleton();
container.Register<INancyBootstrapper, TinyNancyBootstrapper>().AsSingleton();
container.Register<IAnnouncer, MigrationLogger>().AsSingleton();
container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>)).AsMultiInstance();
container.InitDatabase();
Instance = 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(
delegate(TinyIoCContainer c, NamedParameterOverloads p)
{
return c.Resolve<IDbFactory>().Create(environmentProvider.GetNzbDroneDatabase());
});
}
private static void AutoRegisterInterfaces(this TinyIoCContainer container, string assemblyName)
{
var assembly = Assembly.Load(assemblyName);
if (assembly == null)
{
throw new ApplicationException("Couldn't load assembly " + assemblyName);
}
var interfaces = assembly.GetInterfaces().Where(c => !c.FullName.StartsWith("Nancy."));
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 = contractType.Assembly.GetImplementations(contractType);
foreach (var implementation in implementations)
{
logger.Trace("Registering {0} as {1}", implementation.Name, contractType.Name);
container.Register(contractType, implementation).AsMultiInstance();
}
}
}
}

@ -12,7 +12,8 @@
<AssemblyName>NzbDrone</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
@ -82,22 +83,22 @@
<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="Exceptron.Client">
<HintPath>..\packages\Exceptron.Client.1.0.20\lib\net20\Exceptron.Client.dll</HintPath>
</Reference>
<Reference Include="Exceptron.NLog">
<HintPath>..\packages\Exceptron.Nlog.1.0.11\lib\net20\Exceptron.NLog.dll</HintPath>
</Reference>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
<Reference Include="FluentMigrator, Version=1.0.6.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\FluentMigrator.1.0.6.0\lib\40\FluentMigrator.dll</HintPath>
</Reference>
<Reference Include="Nancy.Bootstrappers.Autofac, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="FluentMigrator.Runner, Version=1.0.6.0, Culture=neutral, PublicKeyToken=aacfc7de5acabf05, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Nancy.Bootstrappers.Autofac.0.16.1\lib\net40\Nancy.Bootstrappers.Autofac.dll</HintPath>
<HintPath>..\packages\FluentMigrator.1.0.6.0\tools\FluentMigrator.Runner.dll</HintPath>
</Reference>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference>
<Reference Include="Nancy.Hosting.Self">
<HintPath>..\packages\Nancy.Hosting.Self.0.16.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
@ -116,6 +117,7 @@
<Compile Include="ApplicationServer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CommonContainerExtentions.cs" />
<Compile Include="NzbDroneBootstrapper.cs" />
<Compile Include="ApplicationMode.cs" />
<Compile Include="AppMain.cs" />

@ -1,47 +1,26 @@
using System.Reflection;
using Autofac;
using NLog;
using NzbDrone.Api;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Instrumentation;
using TinyIoC;
using NzbDrone.Core;
using NzbDrone.Api;
namespace NzbDrone
{
public static class NzbDroneBootstrapper
{
private static readonly IContainer container;
private static readonly Logger logger = LogManager.GetLogger("NzbDroneBootstrapper");
static NzbDroneBootstrapper()
{
var builder = new ContainerBuilder();
BindKernel(builder);
container = builder.Build();
InitializeApp();
}
public static IContainer Container
{
get
{
return container;
}
}
private static void BindKernel(ContainerBuilder builder)
{
builder.RegisterModule<LogInjectionModule>();
builder.RegisterCommonServices();
builder.RegisterApiServices();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly());
}
private static void InitializeApp()
{
var environmentProvider = container.Resolve<EnvironmentProvider>();
var environmentProvider = ContainerBuilder.Instance.Resolve<EnvironmentProvider>();
ReportingService.RestProvider = container.Resolve<RestProvider>();
ReportingService.RestProvider = ContainerBuilder.Instance.Resolve<RestProvider>();
logger.Info("Start-up Path:'{0}'", environmentProvider.WorkingDirectory);
}

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

@ -1,10 +1,9 @@
<?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="FluentMigrator" version="1.0.6.0" targetFramework="net40" />
<package id="Nancy" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Bootstrappers.Autofac" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" />
<package id="NLog.Config" version="2.0.0.2000" targetFramework="net40" />

Loading…
Cancel
Save