To take full advantage of the repository pattern create an interface that implements the IRepositoryBase interface. All methods from the RepositoryBase will become available to the repository implementing this new interface.

public interface IProductRepository : IRepositoryBase
{
    bool AddProduct(Product product);
    Product FindProductByName(string productName);
}

Implementing this interface will ensure that the repository implementing this interface will provide access to the repository base methods. The repository implementing this interface will also need to implement RepositoryBase.

public class ProductRepository : RepositoryBase<RepositoryContext>, IProductRepository
    {
        public ProductRepository()
            : base(throwExceptions: true)
        {
            base.RepositoryBaseExceptionRaised += ProductRepository_RepositoryBaseExceptionRaised;
        }

        void ProductRepository_RepositoryBaseExceptionRaised(Exception exception)
        {
            throw new NotImplementedException();
        }

        public bool AddProduct(Product product)
        {
            bool result = false;

            result = Add<Product>(product);

            return result;
        }

        public Product FindProductByName(string productName)
        {
            Product result = Find<Product>(x => x.ProductName == productName)
                .FirstOrDefault();

            return result;
        }
    }

Last edited Sep 15, 2012 at 6:55 PM by MMMicha, version 3

Comments

No comments yet.