samedi 21 novembre 2015

Data Repository Pattern Design C#

I have an entity class

public partial class Product
{
    public int ProductId { get; set; }
    public string ProductName { get; set; }
}

and this entity

public partial class User
{
    public User()
    {
        this.Tokens = new HashSet<Token>();
    }

    public int UserId { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Token> Tokens { get; set; }
}

I have a repository pattern

public abstract class DataRepositoryBase<T> : IDataRepository<T>
       where T : class, new()
{
        protected abstract T AddEntity(T entity);

        protected abstract T UpdateEntity(T entity);

        protected abstract IEnumerable<T> GetEntities();

        protected abstract T GetEntity(int id);
}

How can I call repository using generic data repository using some thing like this.<T> just using generic interface not creating new class? Thanks.

_datarepositorypattern.GetDataRepository<IProductRepository>();
_datarepositorypattern.GetDataRepository<IUserRepository>();

Aucun commentaire:

Enregistrer un commentaire