|
|
@ -1,28 +1,34 @@
|
|
|
|
using System;
|
|
|
|
using TinyIoC;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Reflection;
|
|
|
|
using Nancy;
|
|
|
|
using Nancy;
|
|
|
|
using Nancy.Bootstrapper;
|
|
|
|
|
|
|
|
using Nancy.Diagnostics;
|
|
|
|
using Nancy.Diagnostics;
|
|
|
|
using TinyIoC;
|
|
|
|
using Nancy.Bootstrapper;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api
|
|
|
|
namespace NzbDrone.Api
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// TinyIoC bootstrapper - registers default route resolver and registers itself as
|
|
|
|
|
|
|
|
/// INancyModuleCatalog for resolving modules but behaviour can be overridden if required.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public class TinyIoCNancyBootstrapper : NancyBootstrapperWithRequestContainerBase<TinyIoCContainer>
|
|
|
|
public class TinyIoCNancyBootstrapper : NancyBootstrapperWithRequestContainerBase<TinyIoCContainer>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Default assemblies that are ignored for autoregister
|
|
|
|
/// Default assemblies that are ignored for autoregister
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private static readonly IEnumerable<Func<Assembly, bool>> DefaultAutoRegisterIgnoredAssemblies = new Func<Assembly, bool>[]
|
|
|
|
public static IEnumerable<Func<Assembly, bool>> DefaultAutoRegisterIgnoredAssemblies = new Func<Assembly, bool>[]
|
|
|
|
{
|
|
|
|
{
|
|
|
|
asm => !asm.FullName.StartsWith("Nancy.", StringComparison.InvariantCulture),
|
|
|
|
asm => !asm.FullName.StartsWith("Nancy.", StringComparison.InvariantCulture),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the assemblies to ignore when autoregistering the application container
|
|
|
|
/// Gets the assemblies to ignore when autoregistering the application container
|
|
|
|
/// Return true from the delegate to ignore that particular assembly, returning true
|
|
|
|
/// Return true from the delegate to ignore that particular assembly, returning false
|
|
|
|
/// does not mean the assembly *will* be included, a false from another delegate will
|
|
|
|
/// does not mean the assembly *will* be included, a true from another delegate will
|
|
|
|
/// take precedence.
|
|
|
|
/// take precedence.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
protected virtual IEnumerable<Func<Assembly, bool>> AutoRegisterIgnoredAssemblies
|
|
|
|
protected virtual IEnumerable<Func<Assembly, bool>> AutoRegisterIgnoredAssemblies
|
|
|
@ -49,11 +55,6 @@ namespace NzbDrone.Api
|
|
|
|
return this.ApplicationContainer.Resolve<INancyEngine>();
|
|
|
|
return this.ApplicationContainer.Resolve<INancyEngine>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* protected override IModuleKeyGenerator GetModuleKeyGenerator()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return ApplicationContainer.Resolve<IModuleKeyGenerator>();
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Create a default, unconfigured, container
|
|
|
|
/// Create a default, unconfigured, container
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -93,6 +94,7 @@ namespace NzbDrone.Api
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Lifetime.PerRequest:
|
|
|
|
case Lifetime.PerRequest:
|
|
|
|
throw new InvalidOperationException("Unable to directly register a per request lifetime.");
|
|
|
|
throw new InvalidOperationException("Unable to directly register a per request lifetime.");
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -104,10 +106,10 @@ namespace NzbDrone.Api
|
|
|
|
/// by IEnumerable{Type} constructor dependencies.
|
|
|
|
/// by IEnumerable{Type} constructor dependencies.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="container">Container to register into</param>
|
|
|
|
/// <param name="container">Container to register into</param>
|
|
|
|
/// <param name="collectionTypeRegistrationsn">Collection type registrations to register</param>
|
|
|
|
/// <param name="collectionTypeRegistrations">Collection type registrations to register</param>
|
|
|
|
protected override sealed void RegisterCollectionTypes(TinyIoCContainer container, IEnumerable<CollectionTypeRegistration> collectionTypeRegistrationsn)
|
|
|
|
protected override sealed void RegisterCollectionTypes(TinyIoCContainer container, IEnumerable<CollectionTypeRegistration> collectionTypeRegistrations)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var collectionTypeRegistration in collectionTypeRegistrationsn)
|
|
|
|
foreach (var collectionTypeRegistration in collectionTypeRegistrations)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (collectionTypeRegistration.Lifetime)
|
|
|
|
switch (collectionTypeRegistration.Lifetime)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -119,6 +121,7 @@ namespace NzbDrone.Api
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Lifetime.PerRequest:
|
|
|
|
case Lifetime.PerRequest:
|
|
|
|
throw new InvalidOperationException("Unable to directly register a per request lifetime.");
|
|
|
|
throw new InvalidOperationException("Unable to directly register a per request lifetime.");
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -160,8 +163,9 @@ namespace NzbDrone.Api
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a per request child/nested container
|
|
|
|
/// Creates a per request child/nested container
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="context">Current context</param>
|
|
|
|
/// <returns>Request container instance</returns>
|
|
|
|
/// <returns>Request container instance</returns>
|
|
|
|
protected override sealed TinyIoCContainer CreateRequestContainer()
|
|
|
|
protected override TinyIoCContainer CreateRequestContainer(NancyContext context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return this.ApplicationContainer.GetChildContainer();
|
|
|
|
return this.ApplicationContainer.GetChildContainer();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -216,7 +220,7 @@ namespace NzbDrone.Api
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Retreive a specific module instance from the container
|
|
|
|
/// Retrieve a specific module instance from the container
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="container">Container to use</param>
|
|
|
|
/// <param name="container">Container to use</param>
|
|
|
|
/// <param name="moduleType">Type of the module</param>
|
|
|
|
/// <param name="moduleType">Type of the module</param>
|
|
|
@ -239,4 +243,4 @@ namespace NzbDrone.Api
|
|
|
|
container.AutoRegister(AppDomain.CurrentDomain.GetAssemblies().Where(a => !ignoredAssemblies.Any(ia => ia(a))), DuplicateImplementationActions.RegisterMultiple, t => t.Assembly != assembly);
|
|
|
|
container.AutoRegister(AppDomain.CurrentDomain.GetAssemblies().Where(a => !ignoredAssemblies.Any(ia => ia(a))), DuplicateImplementationActions.RegisterMultiple, t => t.Assembly != assembly);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|