Remove a bit of untested code through interface separation

This commit is contained in:
Antony Male 2015-02-20 15:35:12 +00:00
parent 25e90926a4
commit 558b8b70d4
3 changed files with 20 additions and 16 deletions

View File

@ -315,16 +315,21 @@ namespace StyletIoC.Internal
return this.GetRegistrations(new TypeKey(type, key), searchGetAllTypes).GetAll();
}
internal IRegistrationCollection GetRegistrations(TypeKey typeKey, bool searchGetAllTypes)
internal IReadOnlyRegistrationCollection GetRegistrations(TypeKey typeKey, bool searchGetAllTypes)
{
this.CheckDisposed();
IRegistrationCollection registrations;
IReadOnlyRegistrationCollection readOnlyRegistrations;
IRegistrationCollection registrations;
// Try to get registrations. If there are none, see if we can add some from unbound generics
if (!this.registrations.TryGetValue(typeKey, out registrations) &&
!this.TryCreateFuncFactory(typeKey, out registrations) &&
!this.TryCreateGenericTypesForUnboundGeneric(typeKey, out registrations))
if (this.registrations.TryGetValue(typeKey, out registrations) ||
this.TryCreateFuncFactory(typeKey, out registrations) ||
this.TryCreateGenericTypesForUnboundGeneric(typeKey, out registrations))
{
readOnlyRegistrations = registrations;
}
else
{
if (searchGetAllTypes)
{
@ -334,16 +339,16 @@ namespace StyletIoC.Internal
throw new StyletIoCRegistrationException(String.Format("No registrations found for service {0}.", typeKey.Type.GetDescription()));
// Got this far? Good. There's actually a 'get all' collection type. Proceed with that
registrations = new SingleRegistration(registration);
readOnlyRegistrations = new SingleRegistration(registration);
}
else
{
// This will throw a StyletIoCRegistrationException if GetSingle is requested
registrations = new EmptyRegistrationCollection(typeKey.Type);
readOnlyRegistrations = new EmptyRegistrationCollection(typeKey.Type);
}
}
return registrations;
return readOnlyRegistrations;
}
internal IRegistrationCollection AddRegistration(TypeKey typeKey, IRegistration registration)

View File

@ -3,10 +3,14 @@ using System.Collections.Generic;
namespace StyletIoC.Internal
{
internal interface IRegistrationCollection
internal interface IRegistrationCollection : IReadOnlyRegistrationCollection
{
IRegistrationCollection AddRegistration(IRegistration registration);
}
internal interface IReadOnlyRegistrationCollection
{
IRegistration GetSingle();
List<IRegistration> GetAll();
IRegistrationCollection AddRegistration(IRegistration registration);
}
}

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace StyletIoC.Internal.RegistrationCollections
{
internal class EmptyRegistrationCollection : IRegistrationCollection
internal class EmptyRegistrationCollection : IReadOnlyRegistrationCollection
{
private readonly Type type;
@ -22,10 +22,5 @@ namespace StyletIoC.Internal.RegistrationCollections
{
return new List<IRegistration>();
}
public IRegistrationCollection AddRegistration(IRegistration registration)
{
return new SingleRegistration(registration);
}
}
}