Guest User

Untitled

a guest
May 27th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public class EntityMatcher
  2. {
  3. private readonly CompositeFilter<Type> _typeFilters = new CompositeFilter<Type>();
  4. private readonly EntityDetailsUrlPolicy _urlPolicy = new EntityDetailsUrlPolicy();
  5. private readonly IEntityViewModelResolver _entityViewModelResolver;
  6. private BehaviorGraph _graph;
  7.  
  8. public EntityMatcher(IEntityViewModelResolver entityViewModelResolver)
  9. {
  10. _entityViewModelResolver = entityViewModelResolver;
  11. }
  12.  
  13. public CompositeFilter<Type> TypeFilters { get { return _typeFilters; } set { } }
  14.  
  15. public void BuildBehaviors(TypePool pool, BehaviorGraph graph)
  16. {
  17. _graph = graph;
  18. pool.TypesMatching(TypeFilters.Matches).Each(RegisterBehavior);
  19. _graph = null;
  20. }
  21.  
  22. private void RegisterBehavior(Type entityType)
  23. {
  24. var requestModelType = _entityViewModelResolver.GetRequestModel(entityType);
  25. var detailsModelType = _entityViewModelResolver.GetDetailsModel(entityType);
  26.  
  27. bool detailsEndpointNotRequired = requestModelType == null && detailsModelType == null;
  28. if(detailsEndpointNotRequired)
  29. {
  30. return;
  31. }
  32.  
  33. var behaviorType = typeof(RenderEntityDetailsAction<,,>)
  34. .MakeGenericType(entityType, requestModelType, detailsModelType);
  35.  
  36. var targetMethod = behaviorType
  37. .GetMethods(BindingFlags.Public | BindingFlags.Instance)
  38. .Single(m => m.Name == "Get");
  39.  
  40. var call = new ActionCall(behaviorType, targetMethod);
  41. var chain = new BehaviorChain();
  42. chain.AddToEnd(call);
  43. chain.Route = _urlPolicy.Build(call);
  44.  
  45. _graph.AddChain(chain);
  46. }
  47. }
Add Comment
Please, Sign In to add comment