﻿using System;
using System.Web;
using System.Web.Routing;

namespace Corelicious.Web.Routing {
    public class DelegatingHttpHandler : IHttpHandler {
        private readonly Action<RequestContext> _action;
        private readonly RouteData _routeData;

        public DelegatingHttpHandler(Action<RequestContext> action, RouteData routeData) {
            _action = action;
            _routeData = routeData;
        }

        public void ProcessRequest(HttpContext context) {
            var contextBase = new HttpContextWrapper(context);
            var requestContext = new RequestContext(contextBase, _routeData);
            _action(requestContext);
        }

        public Boolean IsReusable {
            get {
                return false;
            }
        }
    }
}
