Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Created Issue: Improve our versioning story with same controller name but under different namespace [834]

$
0
0
If one has two TestController types under different namespace, it is very hard to pick the right one based on the route it came on. Our default controller selector would throw exceptions on multiple matching types.

public virtual HttpControllerDescriptor SelectController(HttpRequestMessage request)
{
if (request == null)
{
throw Error.ArgumentNull("request");
}

string controllerName = GetControllerName(request);
if (String.IsNullOrEmpty(controllerName))
{
throw new HttpResponseException(request.CreateErrorResponse(
HttpStatusCode.NotFound,
Error.Format(SRResources.ResourceNotFound, request.RequestUri),
Error.Format(SRResources.ControllerNameNotFound, request.RequestUri)));
}

HttpControllerDescriptor controllerDescriptor;
if (_controllerInfoCache.Value.TryGetValue(controllerName, out controllerDescriptor))
{
return controllerDescriptor;
}

ICollection<Type> matchingTypes = _controllerTypeCache.GetControllerTypes(controllerName);

// ControllerInfoCache is already initialized.
Contract.Assert(matchingTypes.Count != 1);

if (matchingTypes.Count == 0)
{
// no matching types
throw new HttpResponseException(request.CreateErrorResponse(
HttpStatusCode.NotFound,
Error.Format(SRResources.ResourceNotFound, request.RequestUri),
Error.Format(SRResources.DefaultControllerFactory_ControllerNameNotFound, controllerName)));
}
else
{
// multiple matching types
throw CreateAmbiguousControllerException(request.GetRouteData().Route, controllerName, matchingTypes);
}
}

If the routes look like, where user want to create the right TestController based which route the request came, it is difficult to do today. We should improve the story here.

config.Routes.MapHttpRoute(
name: "HelloV1",
routeTemplate: "api/v1/hello",
defaults: new { id = RouteParameter.Optional, controller = "Test", action = "Hello" }
);

// Controller: MvcApplication1.Controllers.V2.Test
config.Routes.MapHttpRoute(
name: "HelloV2",
routeTemplate: "api/v2/hello_v2",
defaults: new { id = RouteParameter.Optional, controller = "Test", action = "Hello_V2" }
);


Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>