public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            var config = GlobalConfiguration.Configuration;

            //config.Formatters.Clear();
            config.Formatters.Add(new ImageFromTextFormatter());
            config.Formatters.Add(new WaveFromTextFormatter());
            config.Formatters.Add(new CsvMediaTypeFormatter());

            var controllerFactory = config.ServiceResolver.GetHttpControllerFactory();
            config.ServiceResolver.SetService(typeof(IHttpControllerFactory), new ParentChildControllerFactory(controllerFactory));

            config.Routes.MapHttpRoute(
                "parent",
                "api/{parent}/{id}/{controller}/{childId}",
                new { childId = RouteParameter.Optional });

            config.Routes.MapHttpRoute(
                "ApiDefault",
                "api/{controller}/{id}",
                new {id = RouteParameter.Optional});

            var counter = new Counter();
            config.MessageHandlers.Add(new RequestCountHandler(counter));
            //config.MessageHandlers.Add(new ApiKeyMessageHandler());

            //config.ServiceResolver.SetService(typeof (CounterController), new CounterController(counter));
            config.ServiceResolver.SetResolver(
                type => type == typeof(CounterController) ? new CounterController(counter) : null,
                type => new object[0]
                );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }
 public RequestCountHandler(Counter counter)
 {
     _counter = counter;
 }
 public CounterController(Counter counter)
 {
     _counter = counter;
 }