Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EntityMatcher
- {
- private readonly CompositeFilter<Type> _typeFilters = new CompositeFilter<Type>();
- private readonly EntityDetailsUrlPolicy _urlPolicy = new EntityDetailsUrlPolicy();
- private readonly IEntityViewModelResolver _entityViewModelResolver;
- private BehaviorGraph _graph;
- public EntityMatcher(IEntityViewModelResolver entityViewModelResolver)
- {
- _entityViewModelResolver = entityViewModelResolver;
- }
- public CompositeFilter<Type> TypeFilters { get { return _typeFilters; } set { } }
- public void BuildBehaviors(TypePool pool, BehaviorGraph graph)
- {
- _graph = graph;
- pool.TypesMatching(TypeFilters.Matches).Each(RegisterBehavior);
- _graph = null;
- }
- private void RegisterBehavior(Type entityType)
- {
- var requestModelType = _entityViewModelResolver.GetRequestModel(entityType);
- var detailsModelType = _entityViewModelResolver.GetDetailsModel(entityType);
- bool detailsEndpointNotRequired = requestModelType == null && detailsModelType == null;
- if(detailsEndpointNotRequired)
- {
- return;
- }
- var behaviorType = typeof(RenderEntityDetailsAction<,,>)
- .MakeGenericType(entityType, requestModelType, detailsModelType);
- var targetMethod = behaviorType
- .GetMethods(BindingFlags.Public | BindingFlags.Instance)
- .Single(m => m.Name == "Get");
- var call = new ActionCall(behaviorType, targetMethod);
- var chain = new BehaviorChain();
- chain.AddToEnd(call);
- chain.Route = _urlPolicy.Build(call);
- _graph.AddChain(chain);
- }
- }
Add Comment
Please, Sign In to add comment