|
|
|
@ -1,28 +1,34 @@
|
|
|
|
|
using System;
|
|
|
|
|
using TinyIoC;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Nancy;
|
|
|
|
|
using Nancy.Bootstrapper;
|
|
|
|
|
using Nancy.Diagnostics;
|
|
|
|
|
using TinyIoC;
|
|
|
|
|
using Nancy.Bootstrapper;
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
{
|
|
|
|
|
// <summary>
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Default assemblies that are ignored for autoregister
|
|
|
|
|
/// </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),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the assemblies to ignore when autoregistering the application container
|
|
|
|
|
/// Return true from the delegate to ignore that particular assembly, returning true
|
|
|
|
|
/// does not mean the assembly *will* be included, a false from another delegate will
|
|
|
|
|
/// Return true from the delegate to ignore that particular assembly, returning false
|
|
|
|
|
/// does not mean the assembly *will* be included, a true from another delegate will
|
|
|
|
|
/// take precedence.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual IEnumerable<Func<Assembly, bool>> AutoRegisterIgnoredAssemblies
|
|
|
|
@ -49,11 +55,6 @@ namespace NzbDrone.Api
|
|
|
|
|
return this.ApplicationContainer.Resolve<INancyEngine>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* protected override IModuleKeyGenerator GetModuleKeyGenerator()
|
|
|
|
|
{
|
|
|
|
|
return ApplicationContainer.Resolve<IModuleKeyGenerator>();
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a default, unconfigured, container
|
|
|
|
|
/// </summary>
|
|
|
|
@ -93,6 +94,7 @@ namespace NzbDrone.Api
|
|
|
|
|
break;
|
|
|
|
|
case Lifetime.PerRequest:
|
|
|
|
|
throw new InvalidOperationException("Unable to directly register a per request lifetime.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
@ -104,10 +106,10 @@ namespace NzbDrone.Api
|
|
|
|
|
/// 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)
|
|
|
|
|
/// <param name="collectionTypeRegistrations">Collection type registrations to register</param>
|
|
|
|
|
protected override sealed void RegisterCollectionTypes(TinyIoCContainer container, IEnumerable<CollectionTypeRegistration> collectionTypeRegistrations)
|
|
|
|
|
{
|
|
|
|
|
foreach (var collectionTypeRegistration in collectionTypeRegistrationsn)
|
|
|
|
|
foreach (var collectionTypeRegistration in collectionTypeRegistrations)
|
|
|
|
|
{
|
|
|
|
|
switch (collectionTypeRegistration.Lifetime)
|
|
|
|
|
{
|
|
|
|
@ -119,6 +121,7 @@ namespace NzbDrone.Api
|
|
|
|
|
break;
|
|
|
|
|
case Lifetime.PerRequest:
|
|
|
|
|
throw new InvalidOperationException("Unable to directly register a per request lifetime.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
@ -160,8 +163,9 @@ namespace NzbDrone.Api
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a per request child/nested container
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="context">Current context</param>
|
|
|
|
|
/// <returns>Request container instance</returns>
|
|
|
|
|
protected override sealed TinyIoCContainer CreateRequestContainer()
|
|
|
|
|
protected override TinyIoCContainer CreateRequestContainer(NancyContext context)
|
|
|
|
|
{
|
|
|
|
|
return this.ApplicationContainer.GetChildContainer();
|
|
|
|
|
}
|
|
|
|
@ -216,7 +220,7 @@ namespace NzbDrone.Api
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retreive a specific module instance from the container
|
|
|
|
|
/// Retrieve a specific module instance from the container
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="container">Container to use</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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|