我有一个事件在我的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);
}
}