mirror of https://github.com/AMT-Cheif/Stylet.git
Remove a bit of untested code through interface separation
This commit is contained in:
parent
25e90926a4
commit
558b8b70d4
|
@ -315,16 +315,21 @@ namespace StyletIoC.Internal
|
||||||
return this.GetRegistrations(new TypeKey(type, key), searchGetAllTypes).GetAll();
|
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();
|
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
|
// Try to get registrations. If there are none, see if we can add some from unbound generics
|
||||||
if (!this.registrations.TryGetValue(typeKey, out registrations) &&
|
if (this.registrations.TryGetValue(typeKey, out registrations) ||
|
||||||
!this.TryCreateFuncFactory(typeKey, out registrations) &&
|
this.TryCreateFuncFactory(typeKey, out registrations) ||
|
||||||
!this.TryCreateGenericTypesForUnboundGeneric(typeKey, out registrations))
|
this.TryCreateGenericTypesForUnboundGeneric(typeKey, out registrations))
|
||||||
|
{
|
||||||
|
readOnlyRegistrations = registrations;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (searchGetAllTypes)
|
if (searchGetAllTypes)
|
||||||
{
|
{
|
||||||
|
@ -334,16 +339,16 @@ namespace StyletIoC.Internal
|
||||||
throw new StyletIoCRegistrationException(String.Format("No registrations found for service {0}.", typeKey.Type.GetDescription()));
|
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
|
// Got this far? Good. There's actually a 'get all' collection type. Proceed with that
|
||||||
registrations = new SingleRegistration(registration);
|
readOnlyRegistrations = new SingleRegistration(registration);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This will throw a StyletIoCRegistrationException if GetSingle is requested
|
// 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)
|
internal IRegistrationCollection AddRegistration(TypeKey typeKey, IRegistration registration)
|
||||||
|
|
|
@ -3,10 +3,14 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace StyletIoC.Internal
|
namespace StyletIoC.Internal
|
||||||
{
|
{
|
||||||
internal interface IRegistrationCollection
|
internal interface IRegistrationCollection : IReadOnlyRegistrationCollection
|
||||||
|
{
|
||||||
|
IRegistrationCollection AddRegistration(IRegistration registration);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal interface IReadOnlyRegistrationCollection
|
||||||
{
|
{
|
||||||
IRegistration GetSingle();
|
IRegistration GetSingle();
|
||||||
List<IRegistration> GetAll();
|
List<IRegistration> GetAll();
|
||||||
IRegistrationCollection AddRegistration(IRegistration registration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace StyletIoC.Internal.RegistrationCollections
|
namespace StyletIoC.Internal.RegistrationCollections
|
||||||
{
|
{
|
||||||
internal class EmptyRegistrationCollection : IRegistrationCollection
|
internal class EmptyRegistrationCollection : IReadOnlyRegistrationCollection
|
||||||
{
|
{
|
||||||
private readonly Type type;
|
private readonly Type type;
|
||||||
|
|
||||||
|
@ -22,10 +22,5 @@ namespace StyletIoC.Internal.RegistrationCollections
|
||||||
{
|
{
|
||||||
return new List<IRegistration>();
|
return new List<IRegistration>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IRegistrationCollection AddRegistration(IRegistration registration)
|
|
||||||
{
|
|
||||||
return new SingleRegistration(registration);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue