Created
June 21, 2013 20:22
-
-
Save mmertsock/5834047 to your computer and use it in GitHub Desktop.
FallbackRegistrationProvider for TinyIoC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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