If I'm not mistaken, you are basically looking for a hook where you can examine the final route prefix or route pattern generated by the web api attribute routing probing mechanism and modify them before they are added to the route table. Thus, you can connect third-party modules with attribute controllers and modify their route patterns so that they cannot interact with other modules or your own application routes ... is this correct?
Web API , IRoutePrefix RoutePrefixAttribute ( IRoutePrefix), RoutePrefixes, . , , , .
, Web API . , - .
:
.
, , , . , , . , , , RouteAttribute...
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
public class MyRouteAttribute : Attribute, IDirectRouteFactory
{
private readonly string _template;
public MyRouteAttribute(string template)
{
_template = template;
}
public string Template
{
get { return _template; }
}
public string Name { get; set; }
public int Order { get; set; }
public virtual IDictionary<string, object> Defaults
{
get { return null; }
}
public virtual IDictionary<string, object> Constraints
{
get { return null; }
}
public virtual IDictionary<string, object> DataTokens
{
get { return null; }
}
public RouteEntry CreateRoute(DirectRouteFactoryContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
IDirectRouteBuilder builder = context.CreateBuilder(Template);
string finalTemplate = builder.Template;
builder.Template = "modulename/" + finalTemplate;
builder.Name = Name;
builder.Order = Order;
IDictionary<string, object> builderDefaults = builder.Defaults;
if (builderDefaults == null)
{
builder.Defaults = Defaults;
}
else
{
IDictionary<string, object> defaults = Defaults;
if (defaults != null)
{
foreach (KeyValuePair<string, object> defaultItem in defaults)
{
builderDefaults[defaultItem.Key] = defaultItem.Value;
}
}
}
IDictionary<string, object> builderConstraints = builder.Constraints;
if (builderConstraints == null)
{
builder.Constraints = Constraints;
}
else
{
IDictionary<string, object> constraints = Constraints;
if (constraints != null)
{
foreach (KeyValuePair<string, object> constraint in constraints)
{
builderConstraints[constraint.Key] = constraint.Value;
}
}
}
IDictionary<string, object> builderDataTokens = builder.DataTokens;
if (builderDataTokens == null)
{
builder.DataTokens = DataTokens;
}
else
{
IDictionary<string, object> dataTokens = DataTokens;
if (dataTokens != null)
{
foreach (KeyValuePair<string, object> dataToken in dataTokens)
{
builderDataTokens[dataToken.Key] = dataToken.Value;
}
}
}
return builder.Build();
}
}