Skip to content

Instantly share code, notes, and snippets.

@mmertsock
Created June 21, 2013 20:22
Show Gist options
  • Save mmertsock/5834047 to your computer and use it in GitHub Desktop.
Save mmertsock/5834047 to your computer and use it in GitHub Desktop.
FallbackRegistrationProvider for TinyIoC
internal interface IFallbackRegistrationProvider
{
bool TryRegister(Type registerType, TinyIoCContainer container);
}
internal sealed class TinyIoCContainer : IDisposable
{
public IFallbackRegistrationProvider FallbackRegistrationProvider { get; set; }
private class NullFallbackRegistrationProvider : IFallbackRegistrationProvider
{
public bool TryRegister(Type registerType, TinyIoCContainer container)
{
return false;
}
}
// etc.
public TinyIoCContainer()
{
FallbackRegistrationProvider = new NullFallbackRegistrationProvider();
// etc.
}
// etc.
// add param with default:
private object ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, bool attemptFallback = true)
{
// add a new if statement to the end of the method:
if (attemptFallback && FallbackRegistrationProvider.TryRegister(registration.Type, this))
return ResolveInternal(registration, parameters, false);
// Unable to resolve - throw
throw new TinyIoCResolutionException(registration.Type);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment