c# - ASP.NET web api controller not working when injecting service

125 views Asked by At

When i input interface/services my API is not get, but when i commented my interface/services, it works. ill try using different API with the same code as this and it works.

Controller:

    private readonly IUnitOfWorkAsync _unitOfWork;
    private readonly IDivMapItemListService _divMapItem;

    public DivMapItemListController(IUnitOfWorkAsync unitOfWork, IDivMapItemListService divMapItem)
    {
        _unitOfWork = unitOfWork;
        _divMapItem = divMapItem;
    }

    [HttpGet]
    [AllowAnonymous]
    [Route("api/item/list")]
    public IHttpActionResult DailyItemList()
    {
        _unitOfWork.BeginTransaction();
        try
        {
            var data = _divMapItem.DailyInsert();

            return Ok();
        }
        catch (Exception ex)
        {
            _unitOfWork.Rollback();
            return InternalServerError();
        }
    }

Services:

public class DivMapItemListService : Service<DivMapItemList>, IDivMapItemListService
{
    private readonly IRepositoryAsync<DivMapItemList> _repository;

    public DivMapItemListService(IRepositoryAsync<DivMapItemLis> repository) : base(repository)
    {
        _repository = repository;
    }

    public IEnumerable<DivMapItemList> DailyInsert()
    {
        try
        {
            var _currentDate = DateTime.Now.Date;
            int _lastTwoYears = _currentDate.Year - 2;

            var rawData = _repository.GetRepositoryAsync<DivMapItem>().DivMapItemListOpt(_lastTwoYears, _lastTwoYears).ToList();

            return rawData;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}

Interface

    public interface IDivMapItemListService : IService<DivMapItemList>
    {
       IEnumerable<DivMapItemList> DailyInsert();
    }
0

There are 0 answers