Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor code cleanup #18

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 22 additions & 38 deletions src/TinyIoC/TinyIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static TypeExtensions()
/// <returns>MethodInfo or null if no matches found</returns>
/// <exception cref="System.Reflection.AmbiguousMatchException"/>
/// <exception cref="System.ArgumentException"/>
public static MethodInfo GetGenericMethod(this Type sourceType, System.Reflection.BindingFlags bindingFlags, string methodName, Type[] genericTypes, Type[] parameterTypes)
public static MethodInfo GetGenericMethod(this Type sourceType, BindingFlags bindingFlags, string methodName, Type[] genericTypes, Type[] parameterTypes)
{
MethodInfo method;
var cacheKey = new GenericMethodCacheKey(sourceType, methodName, genericTypes, parameterTypes);
Expand Down Expand Up @@ -589,7 +589,7 @@ public RegisterOptions(TinyIoCContainer container, TypeRegistration registration
/// Make registration a singleton (single instance) if possible
/// </summary>
/// <returns>RegisterOptions</returns>
/// <exception cref="TinyIoCInstantiationTypeException"></exception>
/// <exception cref="TinyIoCRegistrationException"></exception>
public RegisterOptions AsSingleton()
{
var currentFactory = _Container.GetCurrentFactory(_Registration);
Expand All @@ -604,7 +604,7 @@ public RegisterOptions AsSingleton()
/// Make registration multi-instance if possible
/// </summary>
/// <returns>RegisterOptions</returns>
/// <exception cref="TinyIoCInstantiationTypeException"></exception>
/// <exception cref="TinyIoCRegistrationException"></exception>
public RegisterOptions AsMultiInstance()
{
var currentFactory = _Container.GetCurrentFactory(_Registration);
Expand All @@ -619,7 +619,7 @@ public RegisterOptions AsMultiInstance()
/// Make registration hold a weak reference if possible
/// </summary>
/// <returns>RegisterOptions</returns>
/// <exception cref="TinyIoCInstantiationTypeException"></exception>
/// <exception cref="TinyIoCRegistrationException"></exception>
public RegisterOptions WithWeakReference()
{
var currentFactory = _Container.GetCurrentFactory(_Registration);
Expand All @@ -634,7 +634,7 @@ public RegisterOptions WithWeakReference()
/// Make registration hold a strong reference if possible
/// </summary>
/// <returns>RegisterOptions</returns>
/// <exception cref="TinyIoCInstantiationTypeException"></exception>
/// <exception cref="TinyIoCRegistrationException"></exception>
public RegisterOptions WithStrongReference()
{
var currentFactory = _Container.GetCurrentFactory(_Registration);
Expand Down Expand Up @@ -718,7 +718,7 @@ public MultiRegisterOptions(IEnumerable<RegisterOptions> registerOptions)
/// Make registration a singleton (single instance) if possible
/// </summary>
/// <returns>RegisterOptions</returns>
/// <exception cref="TinyIoCInstantiationTypeException"></exception>
/// <exception cref="TinyIoCRegistrationException"></exception>
public MultiRegisterOptions AsSingleton()
{
_RegisterOptions = ExecuteOnAllRegisterOptions(ro => ro.AsSingleton());
Expand All @@ -729,7 +729,7 @@ public MultiRegisterOptions AsSingleton()
/// Make registration multi-instance if possible
/// </summary>
/// <returns>MultiRegisterOptions</returns>
/// <exception cref="TinyIoCInstantiationTypeException"></exception>
/// <exception cref="TinyIoCRegistrationException"></exception>
public MultiRegisterOptions AsMultiInstance()
{
_RegisterOptions = ExecuteOnAllRegisterOptions(ro => ro.AsMultiInstance());
Expand Down Expand Up @@ -990,7 +990,7 @@ public RegisterOptions Register(Type registerType, Func<TinyIoCContainer, NamedP
/// <summary>
/// Creates/replaces a container class registration with default options.
/// </summary>
/// <typeparam name="RegisterImplementation">Type to register</typeparam>
/// <typeparam name="RegisterType">Type to register</typeparam>
/// <returns>RegisterOptions for fluent API</returns>
public RegisterOptions Register<RegisterType>()
where RegisterType : class
Expand All @@ -1001,7 +1001,7 @@ public RegisterOptions Register<RegisterType>()
/// <summary>
/// Creates/replaces a named container class registration with default options.
/// </summary>
/// <typeparam name="RegisterImplementation">Type to register</typeparam>
/// <typeparam name="RegisterType">Type to register</typeparam>
/// <param name="name">Name of registration</param>
/// <returns>RegisterOptions for fluent API</returns>
public RegisterOptions Register<RegisterType>(string name)
Expand Down Expand Up @@ -1150,7 +1150,7 @@ public MultiRegisterOptions RegisterMultiple<RegisterType>(IEnumerable<Type> imp
public MultiRegisterOptions RegisterMultiple(Type registrationType, IEnumerable<Type> implementationTypes)
{
if (implementationTypes == null)
throw new ArgumentNullException("types", "types is null.");
throw new ArgumentNullException("implementationTypes", "implementationTypes is null.");

foreach (var type in implementationTypes)
if (!registrationType.IsAssignableFrom(type))
Expand Down Expand Up @@ -1421,7 +1421,6 @@ public ResolveType Resolve<ResolveType>(string name, NamedParameterOverloads par
/// Note: Resolution may still fail if user defined factory registations fail to construct objects when called.
/// </summary>
/// <param name="resolveType">Type to resolve</param>
/// <param name="name">Name of registration</param>
/// <returns>Bool indicating whether the type can be resolved</returns>
public bool CanResolve(Type resolveType)
{
Expand All @@ -1434,6 +1433,7 @@ public bool CanResolve(Type resolveType)
/// Note: Resolution may still fail if user defined factory registations fail to construct objects when called.
/// </summary>
/// <param name="resolveType">Type to resolve</param>
/// <param name="name">Name of registration</param>
/// <returns>Bool indicating whether the type can be resolved</returns>
private bool CanResolve(Type resolveType, string name)
{
Expand All @@ -1446,7 +1446,6 @@ private bool CanResolve(Type resolveType, string name)
/// Note: Resolution may still fail if user defined factory registations fail to construct objects when called.
/// </summary>
/// <param name="resolveType">Type to resolve</param>
/// <param name="name">Name of registration</param>
/// <param name="options">Resolution options</param>
/// <returns>Bool indicating whether the type can be resolved</returns>
public bool CanResolve(Type resolveType, ResolveOptions options)
Expand Down Expand Up @@ -1542,7 +1541,6 @@ public bool CanResolve(Type resolveType, string name, NamedParameterOverloads pa
/// Note: Resolution may still fail if user defined factory registations fail to construct objects when called.
/// </summary>
/// <typeparam name="ResolveType">Type to resolve</typeparam>
/// <param name="name">Name of registration</param>
/// <returns>Bool indicating whether the type can be resolved</returns>
public bool CanResolve<ResolveType>()
where ResolveType : class
Expand All @@ -1569,7 +1567,6 @@ public bool CanResolve<ResolveType>(string name)
/// Note: Resolution may still fail if user defined factory registations fail to construct objects when called.
/// </summary>
/// <typeparam name="ResolveType">Type to resolve</typeparam>
/// <param name="name">Name of registration</param>
/// <param name="options">Resolution options</param>
/// <returns>Bool indicating whether the type can be resolved</returns>
public bool CanResolve<ResolveType>(ResolveOptions options)
Expand Down Expand Up @@ -1668,7 +1665,7 @@ public bool CanResolve<ResolveType>(string name, NamedParameterOverloads paramet
/// <summary>
/// Attemps to resolve a type using the default options
/// </summary>
/// <param name="ResolveType">Type to resolve</param>
/// <param name="resolveType">Type to resolve</param>
/// <param name="resolvedType">Resolved type or default if resolve fails</param>
/// <returns>True if resolved sucessfully, false otherwise</returns>
public bool TryResolve(Type resolveType, out object resolvedType)
Expand All @@ -1688,7 +1685,7 @@ public bool TryResolve(Type resolveType, out object resolvedType)
/// <summary>
/// Attemps to resolve a type using the given options
/// </summary>
/// <param name="ResolveType">Type to resolve</param>
/// <param name="resolveType">Type to resolve</param>
/// <param name="options">Resolution options</param>
/// <param name="resolvedType">Resolved type or default if resolve fails</param>
/// <returns>True if resolved sucessfully, false otherwise</returns>
Expand All @@ -1709,7 +1706,7 @@ public bool TryResolve(Type resolveType, ResolveOptions options, out object reso
/// <summary>
/// Attemps to resolve a type using the default options and given name
/// </summary>
/// <param name="ResolveType">Type to resolve</param>
/// <param name="resolveType">Type to resolve</param>
/// <param name="name">Name of registration</param>
/// <param name="resolvedType">Resolved type or default if resolve fails</param>
/// <returns>True if resolved sucessfully, false otherwise</returns>
Expand All @@ -1730,7 +1727,7 @@ public bool TryResolve(Type resolveType, string name, out object resolvedType)
/// <summary>
/// Attemps to resolve a type using the given options and name
/// </summary>
/// <param name="ResolveType">Type to resolve</param>
/// <param name="resolveType">Type to resolve</param>
/// <param name="name">Name of registration</param>
/// <param name="options">Resolution options</param>
/// <param name="resolvedType">Resolved type or default if resolve fails</param>
Expand All @@ -1752,7 +1749,7 @@ public bool TryResolve(Type resolveType, string name, ResolveOptions options, ou
/// <summary>
/// Attemps to resolve a type using the default options and supplied constructor parameters
/// </summary>
/// <param name="ResolveType">Type to resolve</param>
/// <param name="resolveType">Type to resolve</param>
/// <param name="parameters">User specified constructor parameters</param>
/// <param name="resolvedType">Resolved type or default if resolve fails</param>
/// <returns>True if resolved sucessfully, false otherwise</returns>
Expand All @@ -1773,7 +1770,7 @@ public bool TryResolve(Type resolveType, NamedParameterOverloads parameters, out
/// <summary>
/// Attemps to resolve a type using the default options and supplied name and constructor parameters
/// </summary>
/// <param name="ResolveType">Type to resolve</param>
/// <param name="resolveType">Type to resolve</param>
/// <param name="name">Name of registration</param>
/// <param name="parameters">User specified constructor parameters</param>
/// <param name="resolvedType">Resolved type or default if resolve fails</param>
Expand All @@ -1795,8 +1792,7 @@ public bool TryResolve(Type resolveType, string name, NamedParameterOverloads pa
/// <summary>
/// Attemps to resolve a type using the supplied options and constructor parameters
/// </summary>
/// <param name="ResolveType">Type to resolve</param>
/// <param name="name">Name of registration</param>
/// <param name="resolveType">Type to resolve</param>
/// <param name="parameters">User specified constructor parameters</param>
/// <param name="options">Resolution options</param>
/// <param name="resolvedType">Resolved type or default if resolve fails</param>
Expand All @@ -1818,7 +1814,7 @@ public bool TryResolve(Type resolveType, NamedParameterOverloads parameters, Res
/// <summary>
/// Attemps to resolve a type using the supplied name, options and constructor parameters
/// </summary>
/// <param name="ResolveType">Type to resolve</param>
/// <param name="resolveType">Type to resolve</param>
/// <param name="name">Name of registration</param>
/// <param name="parameters">User specified constructor parameters</param>
/// <param name="options">Resolution options</param>
Expand Down Expand Up @@ -1975,7 +1971,6 @@ public bool TryResolve<ResolveType>(string name, NamedParameterOverloads paramet
/// Attemps to resolve a type using the supplied options and constructor parameters
/// </summary>
/// <typeparam name="ResolveType">Type to resolve</typeparam>
/// <param name="name">Name of registration</param>
/// <param name="parameters">User specified constructor parameters</param>
/// <param name="options">Resolution options</param>
/// <param name="resolvedType">Resolved type or default if resolve fails</param>
Expand Down Expand Up @@ -2022,7 +2017,7 @@ public bool TryResolve<ResolveType>(string name, NamedParameterOverloads paramet
/// <summary>
/// Returns all registrations of a type
/// </summary>
/// <param name="ResolveType">Type to resolveAll</param>
/// <param name="resolveType">Type to resolveAll</param>
/// <param name="includeUnnamed">Whether to include un-named (default) registrations</param>
/// <returns>IEnumerable</returns>
public IEnumerable<object> ResolveAll(Type resolveType, bool includeUnnamed)
Expand All @@ -2033,7 +2028,7 @@ public IEnumerable<object> ResolveAll(Type resolveType, bool includeUnnamed)
/// <summary>
/// Returns all registrations of a type, both named and unnamed
/// </summary>
/// <param name="ResolveType">Type to resolveAll</param>
/// <param name="resolveType">Type to resolveAll</param>
/// <returns>IEnumerable</returns>
public IEnumerable<object> ResolveAll(Type resolveType)
{
Expand All @@ -2056,7 +2051,6 @@ public IEnumerable<ResolveType> ResolveAll<ResolveType>(bool includeUnnamed)
/// Returns all registrations of a type, both named and unnamed
/// </summary>
/// <typeparam name="ResolveType">Type to resolveAll</typeparam>
/// <param name="includeUnnamed">Whether to include un-named (default) registrations</param>
/// <returns>IEnumerable</returns>
public IEnumerable<ResolveType> ResolveAll<ResolveType>()
where ResolveType : class
Expand Down Expand Up @@ -2703,7 +2697,7 @@ public static TinyIoCContainer Current
#region Type Registrations
public sealed class TypeRegistration
{
private int _hashCode;
private readonly int _hashCode;

public Type Type { get; private set; }
public string Name { get; private set; }
Expand Down Expand Up @@ -2901,11 +2895,6 @@ private RegisterOptions AddUpdateRegistration(TypeRegistration typeRegistration,
return new RegisterOptions(this, typeRegistration);
}

private void RemoveRegistration(TypeRegistration typeRegistration)
{
_RegisteredTypes.Remove(typeRegistration);
}

private ObjectFactoryBase GetDefaultObjectFactory(Type registerType, Type registerImplementation)
{
if (registerType.IsInterface || registerType.IsAbstract)
Expand Down Expand Up @@ -3237,11 +3226,6 @@ private IEnumerable<ConstructorInfo> GetTypeConstructors(Type type)
return type.GetConstructors().OrderByDescending(ctor => ctor.GetParameters().Count());
}

private object ConstructType(Type requestedType, Type implementationType, ResolveOptions options)
{
return ConstructType(requestedType, implementationType, null, NamedParameterOverloads.Default, options);
}

private object ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, ResolveOptions options)
{
return ConstructType(requestedType, implementationType, constructor, NamedParameterOverloads.Default, options);
Expand Down