Created
June 28, 2012 21:04
-
-
Save jeremiahredekop/3013888 to your computer and use it in GitHub Desktop.
Get Message Handler For Message
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 static class ContainerExtensions | |
{ | |
public static Delegate GetMessageHandlerForMessage(this ILifetimeScope lifetimeScope, object message) | |
{ | |
MethodInfo methodInfo = typeof(ContainerExtensions) | |
.GetMethods(BindingFlags.Static | BindingFlags.NonPublic) | |
.Single(m => m.Name == "GetMessageHandlerForMessageInternal"); | |
var methodInfo2 = methodInfo.MakeGenericMethod(new[] { message.GetType() }); | |
return (Delegate)methodInfo2.Invoke(null, new[] { lifetimeScope, message }); | |
} | |
private static Action<T> GetMessageHandlerForMessageInternal<T>(ILifetimeScope lifetimeScope, T message) | |
{ | |
var commandHandler = lifetimeScope.Resolve<IHandleMessages<T>>(); | |
return commandHandler.Handle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment