C#投掷无法解决控制器错误

时间:2017-11-20 17:55:41

标签: c# .net asp.net-mvc-4

我是.NET和c#的新手,而且我正在研究POC,当控制器抛出错误时我遇到了问题

System.InvalidOperation Exception {“无法解析控制器:TenantController”}

内部异常详情

没有注册默认实例,无法自动确定类型'GICS.Web.Managers.Interfaces.ITenantManager'

没有为GICS.Web.Managers.Interfaces.ITenantManager指定配置

1。)新的TenantController( ITenantManager的默认值 IRemedyService的默认值

2。)GICS.Web.Controllers.Api.TenantController

3.。)GICS.Web.Controllers.Api.TenantController的实例

4.)Container.GetInstance(GICS.Web.Controllers.Api.TenantController)

TenantController看起来如下:

<body>
  <div class='frame'>
    <div class='heading'>
      <div class='title'>
        Manual Control
      </div>
      <form method='post' action='/' class='back'>
        Back
      </form>
    </div>
    <div>
      <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.</p>
    </div>
    <div class='title'>
      Gadget
    </div>
    <div class='container-input'>
      <input class='enabled_red' id='r0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
      <input class='enabled_green' id='g0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
      <input class='enabled_blue' id='b0' type='range' min='0' max='1023' step='1' oninput='sendRGB(0);' value='0'>
    </div>

  </div>
</body>

</html>

TenantManager界面如下:

using System.Web.Mvc;
using GICS.Web.Controllers.Api.Abstracts;
using GICS.Web.Managers.Interfaces;
using GICS.Web.Services.Interfaces;
using System.Collections.Generic;
using GICS.Web.ViewModels.Tenant;
using GICS.Web.Models.Tenant;

namespace GICS.Web.Controllers.Api
{
    [RoutePrefix("api/tenant")]
    public class TenantController : BaseApiController
    {
        private readonly ITenantManager _tenantsManager;
        private readonly IRemedyService _remedyService;
        private string token;

        public TenantController(ITenantManager tenantsManager, IRemedyService remedyService)
        {
            _tenantsManager = tenantsManager;
            _remedyService = remedyService;
            token = null;
        }

        [HttpGet, Route("{groupId}/{userName}")]
        public JsonResult getTenants(string groupId, string UserName)
        {
            getToken(UserName);
            JsonResult result = Json(null);

            if (token != null)
            {
                var tenants = _tenantsManager.GetTenants(token, groupId);
                List<TenantViewModel> tenantViewModelList = new List<TenantViewModel>();

                foreach (Values x in tenants)
                {
                    TenantViewModel model = new TenantViewModel(x, groupId);
                    tenantViewModelList.Add(model);
                }
                result = Json(tenantViewModelList);
            }
            return result;
        }
    }

Manager的实现是:

using System.Collections.Generic;
using GICS.Web.Models.Tenant;

namespace GICS.Web.Managers.Interfaces
{
    public interface ITenantManager
    {
        IEnumerable<Values> GetTenants(string token, string groupId);
    }
}

我在项目中有其他控制器遵循相同的方法,除了这个以外所有控制器都在工作。有人发现我在这里错了吗?

提前致谢。

0 个答案:

没有答案