尝试创建“ SaleController”类型的控制器时发生错误。确保控制器具有无参数的公共构造函数。“,

时间:2019-10-11 13:01:25

标签: c#

我无法解决此错误。

代码如下:

    public class SaleController : ApiController
    {
    private readonly ISaleService saleServce;
    private readonly ITrace log;

    public SaleController(ISaleService saleServce)
    {
        this.saleServce = saleServce ?? throw new ArgumentNullException(nameof(saleServce));
        this.log = new Trace(new TraceSource("NapLink.Service"));
    }

    // POST: api/Sale
    [ResponseType(typeof(Sale))]
    public async Task<IHttpActionResult> Post(SaleRequestModel sale)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        var saleRequestModel = await this.saleServce.CreateSale(sale, log);

        return this.Ok($"Успешно създадена продажба с УНП {saleRequestModel.UniqueNumber}");
    }

我使用Unity,并且已完成以下操作:

        var container = new UnityContainer();
        container.RegisterType<IDeliveryService, DeliveryService>(new HierarchicalLifetimeManager());
        container.RegisterType<ISaleService, SaleService>(new HierarchicalLifetimeManager());
        container.RegisterType<ITrace, Trace>(new HierarchicalLifetimeManager());
        container.RegisterType<IUtility, Utility>(new HierarchicalLifetimeManager());
        container.RegisterType<IValidator, Validator>(new HierarchicalLifetimeManager());

        config.DependencyResolver = new UnityResolver(container);

我在这里做什么错?当我使用debug时,我什至无法进入控制器对其进行实例化。

0 个答案:

没有答案