내가 Startup.cs
의 ConfigureServices 방법의 의존성 주입 항목을 추가하는 것을 잊었다 :
using System.Collections.Generic;
using CrossSell.Business.Exceptions;
using CrossSell.Business.Interfaces;
using CrossSell.Entities;
using Microsoft.AspNetCore.Mvc;
namespace CrossSell.API.Controllers
{
[Produces("application/json")]
[Route("api/Product")]
public class ProductController : Controller
{
private readonly IProductManager productManager;
public ProductController(IProductManager productManager)
{
this.productManager = productManager;
}
// POST: api/Product
[HttpPost]
public IEnumerable<Opportunity> Post([FromBody]ClientIdentifiable[] clients)
{
try
{
return productManager.GetCrossSellOpportunities(clients);
}
catch (NoInForceOrHistoricalPoliciesException)
{
return new[] { new Opportunity(true, "No In Force or historical policies") };
}
}
}
}
나는 (: 3000 로컬 호스트에서 실행) 내 반작용 응용 프로그램에서 Post 메소드를 호출하고 있습니다
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddTransient<IClientManager, ClientManager>();
services.AddTransient<IClientRepository, ClientRepository>();
// added the following and it hit the web api method correctly
services.AddTransient<IProductManager, ProductManager>();
services.AddTransient<IProductRepository, ProductRepository>();
}
오류를 디버그 할 수 있습니까? 그리고 여러분은'api/product /'대신'/ product /'POST를합니다. –
API/제품을 수정하여 주셔서 감사합니다. 그것은 그 길을 부르고 있습니다. – ParleParle
Funnily enough, @IlyaChumakov 디버그 오류 질문에 대답 할 수 없어서 디버깅을 시작하고 문제를 발견했습니다. – ParleParle