Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellabyte/1524428 to your computer and use it in GitHub Desktop.
Save kellabyte/1524428 to your computer and use it in GitHub Desktop.
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