The problem
When I create a method with a route on the actual controller, say: "api/country/something"...
When I perform the above request, my code gets executed & data gets returned.
But when I try call my route on the base controller. E.G: "api/country/code/123"
I get a 404 error.
Question
Any idea on how to implement generic routes whilst making use of attribute routing?
Specific Controller
[RoutePrefix("Country")]
public class CountryController : MasterDataControllerBase<Country, CountryDto>
{
public CountryController(
IGenericRepository<Country> repository,
IMappingService mapper,
ISecurityService security) : base(repository, mapper, security)
{
}
}
Base
public class MasterDataControllerBase<TEntity, TEntityDto> : ControllerBase
where TEntity : class, ICodedEntity, new()
where TEntityDto : class, new()
{
private readonly IMappingService mapper;
private readonly IGenericRepository<TEntity> repository;
private readonly ISecurityService security;
public MasterDataControllerBase(IGenericRepository<TEntity> repository, IMappingService mapper, ISecurityService security)
{
this.security = security;
this.mapper = mapper;
this.repository = repository;
}
[Route("code/{code}")]
public TEntityDto Get(string code)
{
this.security.Enforce(AccessRight.CanAccessMasterData);
var result = this.repository.FindOne(o => o.Code == code);
return this.mapper.Map<TEntity, TEntityDto>(result);
}
}