0
mgx92 created
Hello community,
I want to replace the web api IHttpControllerSelector service, because I want to use versioning via media types. But when I try it like this:
Configuration.Modules.AbpWebApi().HttpConfiguration.Services.Replace(typeof(IHttpControllerSelector),
new AcceptHeaderControllerSelector(Configuration.Modules.AbpWebApi().HttpConfiguration,
accept =>
{
foreach (var parameter in accept.Parameters)
{
if (parameter.Name.Equals("version", System.StringComparison.InvariantCultureIgnoreCase))
{
switch (parameter.Value)
{
case "1.0": return "v1";
}
}
}
return "v1";
}));
The new AcceptHeaderControllerSelector never called. I don't know what's wrong with this solution.. maybe I have to do it via Configuration.ServiceReplace?
I hope someone can help me.
mxg
2 Answer(s)
-
0
Hi,
Your way seems correct. Where do you run this code ? Is it in the PostInitialize of your webapi module ?
-
0
Oh no, I run this code in the Initialize method... thank you very much - your suggestion works! I put the code into the postInitialize and it works! :)