具有通用类型的控制器无法与API一起使用

时间:2018-07-30 07:49:14

标签: api generics model-view-controller types controller

问题是控制器API不知道API调用存在,我尝试了没有泛型类型的API,但是当我添加TEntity和T时,无法看到这是一个控制器。我正在研究一个需要非常通用的项目,直到需要根据传入的DBContext选择要选择的实体为止。除此之外,除了控制器本身,其他所有东西都在工作。请有人告诉我我所缺少的。

<pre>
//[Authorize]
[Route("api/[controller]")]
[AutoValidateAntiforgeryToken]
public class ProductController<TEntity, T> : Controller  where TEntity : class where T : DbContext, new()
    {
    private ITransaction _transaction;
    private static ISession _session;
    private IConfiguration configuration;
    public static Func<PMR_FMLEntities> _pmrDbContext;
    private static Func<FusionEntities> _fusionDbContext;
    private UnitOfWork<TEntity, T> _pmrUnitOfWork;
    private UnitOfWork<TEntity, T> _fusionUnitOfWork;

    public ProductController(IEntityContext dbContext, ISession session, UnitOfWork<TEntity, T> unitOfWork) : base()
    {
     _transaction = session.BeginTransaction();
    _session = session;
    _fusionUnitOfWork = new UnitOfWork<TEntity, T>(_session, _fusionDbContext);
    _pmrUnitOfWork = new UnitOfWork<TEntity, T>(_session, _pmrDbContext);
    }

    protected void Initialize(UnitOfWork<TEntity, T> unitOfWork)
    {
    _pmrUnitOfWork = unitOfWork;
    _fusionUnitOfWork = unitOfWork;
    }

    [HttpGet("[action]")]
    public JsonResult GetProduct()
    {
    var entity = new PRODUCT();
    var result = _pmrUnitOfWork.EntityRepository.Get(entity as TEntity);

    return Json(result);
    }
}
</pre>

0 个答案:

没有答案