Reputation: 9828
In .NET 4.5 / WebApi 2, i could create a constraint and add it using this code
// add constraint resolvers
var constraintResolver = new DefaultInlineConstraintResolver();
constraintResolver.ConstraintMap.Add("constraintName", typeof(MyCustomConstraint));
// routing
config.MapHttpAttributeRoutes(constraintResolver);
Currently in my Startup.cs file, i just have this
public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider)
{
// Enable Mvc for controllers
app.UseMvc();
// Enable all static file middleware (serving of static files and default files) EXCEPT directory browsing.
app.UseFileServer();
}
But i cannot figure out where to do this i asp.net 5/vNext. Can someone please help? I am using attribute routing on all my controllers
Upvotes: 1
Views: 503
Reputation: 399
You can register in the ConfigureServices section of the Startup class.
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
{
services.Configure<RouteOptions>(options =>
options
.ConstraintMap
.Add("constraintName", typeof(MyCustomConstraint)));
}
Upvotes: 3