将T实体传递给EventHandler

时间:2018-08-01 06:34:41

标签: c# .net repository

我有一个事件在我的ProductManager上触发,我想在我的LoggerRepository中处理它。

问题:如何从该事件处理程序中调用Insert(T entity)并将其传递给entity

public class LoggerRepository<T> : ILoggerRepository<T> where T : class
{
    private readonly IProductsManager _productsManager;
    protected DbSet<T> DbSet;

    public LoggerRepository(IProductsManager productsManager)
    {
        _productsManager = productsManager;
        _productsManager.OnPricesUpdated += _productsManager_OnPricesUpdated;
    }
    public LoggerRepository(DbContext dbContext)
    {
        DbSet = dbContext.Set<T>();
    }
    private void _productsManager_OnPricesUpdated(object sender, System.EventArgs e)
    {
        **//HOW CAN I CALL Insert(entity) here**
    }
    public void Insert(T entity)
    {
        DbSet.Add(entity);
    }
}

0 个答案:

没有答案