为什么我无法访问我的方法?

时间:2016-12-27 10:39:01

标签: c# repository

我有这样的订单:

IRepository(dll) -> IBaseRepository -> IEntityRepository 

 |                        |               |

Repositoyr(dll) -> BaseRepository -> EntityRepository 

我正在使用统一服务定位器,我在IBaseRepository中定义了一些方法并在BaseRepository中实现它们(为了能够在我的所有实体存储库中使用它们)

现在当我在我的Actions中创建EntityRepository的实例时,我可以访问所有Repository方法但是BaseRepository方法没有显示!

public interface IBaseRepository<TEntity> : IRepository<TEntity> where TEntity : class 
{
     void Add(TEntity entity, string currentUserNationalCode, string currentUserIp, byte recordStatus,
        string recordStatusDescription);
    void Update(TEntity entity, string currentUserNationalCode, string currentUserIp, byte recordStatus,
       string recordStatusDescription);
    void Remove(TEntity entity, string currentUserNationalCode, string currentUserIp, byte recordStatus,
        string recordStatusDescription);
}




public abstract class BaseRepository<TEntity> : GenericRepository<TEntity>, IBaseRepository<TEntity> where TEntity : BaseEntity
    {
    //public abstract void Add(TEntity entity, string currentUserNationalCode, string currentUserIp, byte recordStatus,
    //    string recordStatusDescription);

    public void Add(TEntity entity, string currentUserNationalCode, string currentUserIp, byte recordStatus,
        string recordStatusDescription)
    {
        entity.RecordStatus = recordStatus;
        entity.RecordStatusDescription = recordStatusDescription;
        entity.CreatedBy = currentUserNationalCode;
        entity.CreatedDateTime = DateTime.Now;
        entity.CreatorIPAddress = currentUserIp;
        this.Add(entity);
    }

    public void Update(TEntity entity, string currentUserNationalCode, string currentUserIp, byte recordStatus,
        string recordStatusDescription)
    {
        entity.RecordStatus = recordStatus;
        entity.RecordStatusDescription = recordStatusDescription;
        entity.ModifiedBy = currentUserNationalCode;
        entity.ModifiedDateTime = DateTime.Now;
        entity.ModifierIPAddress = currentUserIp;
        this.Update(entity);     
    }

    public void Remove(TEntity entity, string currentUserNationalCode, string currentUserIp, byte recordStatus,
        string recordStatusDescription)
    {
        entity.RecordStatus = recordStatus;
        entity.RecordStatusDescription = recordStatusDescription;
        entity.RemovedBy = currentUserNationalCode;
        entity.RemovedDateTime = DateTime.Now;
        entity.RemoverIPAddress = currentUserIp;
        entity.IsRemoved = true;
        this.Update(entity);
    }
}

我的IEntityRepositoryEnityRepository为空:

public class [Entity]Repository : BaseRepository<Organization>, IOrganizationRepository
{    
}

即使我向我的Entity存储库添加了一些方法,我也无法访问它。 Base Entity是包含我所有实体中的一些日志字段的类。

1 个答案:

答案 0 :(得分:1)

这应该有效:

public class Repository : BaseRepository<Organization>, IOrganizationRepository
{
   public void DoSomethingFancy(TEntity entity, string currentUserNationalCode, string currentUserIp, byte recordStatus,
    string recordStatusDescription)
  {
     base.Add(entity, currentUserNationalCode, currentUserIp, recordStatus,  recordStatusDescription);
  }
}