New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebApi MapHttpAttributeRoutes causes error in IComponent #4775
Comments
Notes for self: odd that it works in the constructor and not in |
Reproduced. Putting |
The problem is caused by
in its own But because your component runs after the Short term, registering your component as follows would work:
because it would insert your component in the first position, ie even before Longer term, it feels that |
Going to fix it properly - in progress. |
PR: #4856 Test: with this in place, a user component should be able to Note: renaming some composers etc = breaking. |
I can confirm this works. The breaking names are not going to affect anyone ... well except for @aaronpowell ;) |
Haha I think I'm good for this one 😛 |
This is similar to issue #4464 but slightly different hence the new issue.
So, in v7 to register my own WebApi routes I'd create a class that implements IApplicationEventHandler and register my routes via the OnApplicationStarted method like this:
GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
In v8, it's suggested to use a class that implements IUserComposer then append a component. Then it's suggested to use the Initialize() method to execute startup functions.
However, if I put GlobalConfiguration.Configuration.MapHttpAttributeRoutes(); inside Initialize() I get the following error:
The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.
If I move the call into the constructor for the class
public RouteConfigComponent() { GlobalConfiguration.Configuration.MapHttpAttributeRoutes(); }
Then the error goes away and routes are registered correctly using attributes e.g.
[Route("api/question/{id}")] public HttpResponseMessage Get(int id) { return Request.CreateResponse(HttpStatusCode.OK); }
The workaround is to have this in the constructor but I'm told this is probably not the desired behaviour and to register it here for review.
The text was updated successfully, but these errors were encountered: