Good afternoon, everyone! I'm using repository pattern for access EDM, and I want develop some kind of rights check using custom attribute AccessByRole
like this:
public abstract class RepositoryBase: IRepository
{
...
[AccessByRole]
public virtual void Add(T entity)
{
....
}
[AccessByRole]
public virtual void Update(T entity)
{
...
}
[AccessByRole]
public virtual void Delete(T entity)
{
...
}
[AccessByRole]
public virtual T GetById(long id)
{
...
}
}
Usage of repository (I'm using Autofac for IoC):
public class Service
{
private readonly IRepository repository;
public Service(IRepository repository)
{
this.repository = reporitory;
}
....
public UpdateUserEntities(...)
{
...
reporitory.Update(T); // There is a need for check user rights before calling this method.
}
}
There is a necessity of checking rights of the User before calling CRUD operations. So my question is: How should the attributes source code look like, so the CRUD operations called after the rights checked?