Created
December 27, 2011 17:18
-
-
Save kellabyte/1524428 to your computer and use it in GitHub Desktop.
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
public interface IViewModelResolver | |
{ | |
IViewModel Resolve(); | |
} | |
public class FunqViewModelResolver : IViewModelResolver | |
{ | |
private readonly Container container; | |
private Dictionary<type , MethodInfo> methods = null; | |
private MethodInfo method = null; | |
public FunqViewModelResolver(Container container) | |
{ | |
this.container = container; | |
method = container.GetType().GetMethod( | |
"Resolve", new Type[0]); | |
methods = new Dictionary<Type,MethodInfo>(); | |
} | |
public IViewModel Resolve(Type viewModelType) | |
{ | |
MethodInfo genericMethod = null; | |
if (!methods.TryGetValue(viewModelType, out genericMethod)) | |
{ | |
genericMethod = method.MakeGenericMethod(viewModelType); | |
methods.Add(viewModelType, genericMethod); | |
} | |
var result = genericMethod.Invoke(container, null); | |
return (IViewModel) result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment