Guest User

Untitled

a guest
Jul 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public class CommandHandlerUrlPolicy : IUrlPolicy
  2. {
  3. public bool Matches(ActionCall call, IConfigurationObserver log)
  4. {
  5. return call.Method.Name == "Handle";
  6. }
  7.  
  8. public IRouteDefinition Build(ActionCall call)
  9. {
  10. call = WrapActionCall(call);
  11.  
  12. var route = call.ToRouteDefinition();
  13. route.Append("Services");
  14. route.Append("Commands");
  15. route.Append(call.HandlerType.Name.Replace("CommandHandler", ""));
  16.  
  17. return route;
  18. }
  19.  
  20. private ServiceActionCall WrapActionCall(ActionCall call)
  21. {
  22. var outerCall = new ServiceActionCall(call);
  23. call.ReplaceWith(outerCall);
  24.  
  25. var validationType = typeof(ServiceValidationBehaviour<>).MakeGenericType(outerCall.InputType());
  26. outerCall.WrapWith(validationType);
  27.  
  28. var jsonBehaviourType = typeof(ServiceOutputRenderBehaviour<>).MakeGenericType(typeof(ServiceCommandOutput));
  29. var outputNode = new OutputNode(jsonBehaviourType);
  30. outerCall.AddToEnd(outputNode);
  31. return outerCall;
  32. }
  33. }
Add Comment
Please, Sign In to add comment