@ -83,7 +83,20 @@ namespace NzbDrone.Api
{
{
foreach ( var typeRegistration in typeRegistrations )
foreach ( var typeRegistration in typeRegistrations )
{
{
container . Register ( typeRegistration . RegistrationType , typeRegistration . ImplementationType ) . AsSingleton ( ) ;
switch ( typeRegistration . Lifetime )
{
case Lifetime . Transient :
container . Register ( typeRegistration . RegistrationType , typeRegistration . ImplementationType ) . AsMultiInstance ( ) ;
break ;
case Lifetime . Singleton :
container . Register ( typeRegistration . RegistrationType , typeRegistration . ImplementationType ) . AsSingleton ( ) ;
break ;
case Lifetime . PerRequest :
throw new InvalidOperationException ( "Unable to directly register a per request lifetime." ) ;
break ;
default :
throw new ArgumentOutOfRangeException ( ) ;
}
}
}
}
}
@ -97,7 +110,20 @@ namespace NzbDrone.Api
{
{
foreach ( var collectionTypeRegistration in collectionTypeRegistrationsn )
foreach ( var collectionTypeRegistration in collectionTypeRegistrationsn )
{
{
container . RegisterMultiple ( collectionTypeRegistration . RegistrationType , collectionTypeRegistration . ImplementationTypes ) ;
switch ( collectionTypeRegistration . Lifetime )
{
case Lifetime . Transient :
container . RegisterMultiple ( collectionTypeRegistration . RegistrationType , collectionTypeRegistration . ImplementationTypes ) . AsMultiInstance ( ) ;
break ;
case Lifetime . Singleton :
container . RegisterMultiple ( collectionTypeRegistration . RegistrationType , collectionTypeRegistration . ImplementationTypes ) . AsSingleton ( ) ;
break ;
case Lifetime . PerRequest :
throw new InvalidOperationException ( "Unable to directly register a per request lifetime." ) ;
break ;
default :
throw new ArgumentOutOfRangeException ( ) ;
}
}
}
}
}
@ -160,13 +186,24 @@ namespace NzbDrone.Api
return this . ApplicationContainer . ResolveAll < IApplicationStartup > ( false ) ;
return this . ApplicationContainer . ResolveAll < IApplicationStartup > ( false ) ;
}
}
/// <summary>
/// Gets all registered request startup tasks
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IRequestStartup"/> instances.</returns>
protected override IEnumerable < IRequestStartup > RegisterAndGetRequestStartupTasks ( TinyIoCContainer container , Type [ ] requestStartupTypes )
{
container . RegisterMultiple ( typeof ( IRequestStartup ) , requestStartupTypes ) ;
return container . ResolveAll < IRequestStartup > ( false ) ;
}
/// <summary>
/// <summary>
/// Gets all registered application registration tasks
/// Gets all registered application registration tasks
/// </summary>
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IApplicationRegistrations"/> instances.</returns>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="I Registrations"/> instances.</returns>
protected override IEnumerable < IApplicationRegistrations > GetApplicationRegistrationTasks ( )
protected override IEnumerable < I Registrations> Get RegistrationTasks( )
{
{
return this . ApplicationContainer . ResolveAll < IApplicationRegistrations > ( false ) ;
return this . ApplicationContainer . ResolveAll < I Registrations> ( false ) ;
}
}
/// <summary>
/// <summary>
@ -201,9 +238,7 @@ namespace NzbDrone.Api
{
{
var assembly = typeof ( NancyEngine ) . Assembly ;
var assembly = typeof ( NancyEngine ) . Assembly ;
var whitelist = new Type [ ] { } ;
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 | | whitelist . Any ( wt = > wt = = t ) ) ;
}
}
}
}
}
}