0
votes

I have service that extends EntityCollectionServiceBase of ngrx\data

@Injectable()
export class ProductService extends EntityCollectionServiceBase<Product> {

  constructor(elementsFactory: EntityCollectionServiceElementsFactory) {

    super('Product', elementsFactory);

  }

and my asp.net controller is like this

[Route("api/[controller]")]
    [ApiController]
    public class ProductController : ApiController
    {
        // GET: api/<ProductController>
        [HttpGet]
        public async Task<ActionResult<ProductsListVm>> GetAll()
        {
            var vm = await Mediator.Send(new GetProductsListQuery());
            return Ok(vm);
        }

        // GET api/<ProductController>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }
}

so when I call GetAll on entity service of ngrx\data it requests {url}/api/products/ while the asp.net web API controller only responds to {url}/api/product/

any configuration or trick to resolve with minimal code

1
what is the different between the urls?Rafi Henig
edited, the product controller only responds to {url}/api/product/Ted Mosby

1 Answers

1
votes

You should define a plural name as follwoing:

import { EntityMetadataMap } from 'ngrx-data';

const entityMetadata: EntityMetadataMap = {
  Product: {},
};

const pluralNames = { Product: 'product' };

export const entityConfig = {
  entityMetadata,
  pluralNames
};