riskfirst / riskfirst.hateoas

Powerful HATEOAS functionality for .NET web api
MIT License
78 stars 25 forks source link

Unable to add multiple routes, while configuring for the HATEOAS library #22

Closed rajamadhu closed 5 years ago

rajamadhu commented 5 years ago

I am having an api like below with two routes (one for backward compatibility)

[HttpGet("~/v2/location/{id:int}", Name = "LocationV2")]
[HttpGet("~/location/{id:int}", Name = "Location")]
public async Task<IActionResult> Getlocation(int id)
{
    ....
    _linksService.AddLinksAsync(locationmodel);
    ....
}

Also, I have configured the Startup like below

 services.AddLinks(config =>
{
    config.UseRelativeHrefs();
    config.ConfigureRelTransformation(transform => transform.Add(ctx => $"{ctx.LinkSpec.RouteName}"));

    config.AddPolicy<Location>(policy =>
    {
        policy.RequireRoutedLink("users", "Get Users for a Location", x => new { id = x.Id });
        policy.RequireRoutedLink("areas", "Get Areas for a Location", x => new { locationId = x.Id });
    });
}); 

I am getting an exception "Multiple custom attributes of the same type found", while trying to call the api. It fails in the AddLinksAsync method. Can someone throw more light on how to resolve the issue?

Your help is much appreciated

Thanks

jamiecoh commented 5 years ago

Hi,

I'm happy to take a look at this, but the more information you can share the better - ideally a simple project which reproduces the problem. But at the very least can you include what locationmodel is defined as?

Just so you know the error "Multiple custom attributes of the same type found" is thrown whenever you use more than one attribute where AllowMultiple is false. The only attribute in this library is LinksAttribute which is set to AllowMultiple=true Thanks

Jamie

rajamadhu commented 5 years ago

Hi Jamie, Thanks for your effects, Please find the sample project below.

In this sample project you can reproduce the same issue , which i am facing.

URL: https://github.com/rajamadhu/RiskFirstHateoas.git

Kindly help me as much you can.

rajamadhu commented 5 years ago

Hi,

I'm happy to take a look at this, but the more information you can share the better - ideally a simple project which reproduces the problem. But at the very least can you include what locationmodel is defined as?

Just so you know the error "Multiple custom attributes of the same type found" is thrown whenever you use more than one attribute where AllowMultiple is false. The only attribute in this library is LinksAttribute which is set to AllowMultiple=true Thanks

Jamie

Hi Jamie,

Thanks for your reply, Please find the sample project below.

In this sample project you can reproduce the same issue .

URL: https://github.com/rajamadhu/RiskFirstHateoas.git

Your help is much appreciated

Thanks! Raja Madhu

jamiecoh commented 5 years ago

This bug has been fixed. I will deploy a new version to nuget shortly.

Thanks

Jamie