In .NET 5 this was working, but since moving to .NET 6 and using the more minimal WebApplication to spin up a REST API, I've hit a wall.
To replicate this, I create a simple .NET 6 Console App and in the Main entrypoint, I call:
WebApplicationBuilder builder = WebApplication.CreateBuilder();
builder.Services.AddControllers();
builder.WebHost.ConfigureKestrel(opts => opts.ListenAnyIP(3000));
WebApplication app = builder.Build();
app.UseRouting();
app.MapControllers();
app.Run();
I have a single controller that looks something like this:
[ApiController]
public class SomeController : Controller {
[HttpGet]
[Route("/app/{*thing}")]
public IActionResult DoSomething([FromRoute] String thing) {
return new ObjectResult("route: " + thing);
}
}
This all works fine and if I hit localhost:3000/app/foo, the request is routed and I see "route: foo".
But, if I move the Controller and WebApplication startup code into a referenced class library project, (e.g. in a method called Run) the HTTP server spins up and starts listening, but no matter what I do with routing, the controller in the class library is never picked up and every route results in a 404.
Is there a way to still use attribute routing in a class library, or do we now have to use explicit routes??