ProductService in Sample

Nov 5, 2014 at 3:35 PM
Hello,
i'm pretty new in that patterns, I red few articles and so on. I decided to try use that framework from begining, I don't even know why ;].

So don't be cruel about my newbie Question. I tried to make ProductService in the same way as CustomerService is coded. So I have:


Nortwind.Repository\ProductRepository.cs
public static class ProductRepository
    {
        public static IEnumerable<Product> GetProductByName(this IRepository<Product> repository, string name)
        {
            return repository
                .Queryable()ProductRepository.cs
                .Where(x => x.ProductName.Contains(name))
                .AsEnumerable();
        }
    }
Northwind.Service\ProductService.cs
 public interface IProductService : IService<Product>
    {
        IEnumerable<Product> GetProductByPermission(string name);
    }

    public class ProductService : Service<Product>, IProductService
    {
        public ProductService(IRepositoryAsync<Product> repository)
            : base(repository)
        {
            _repository = repository;
        }

        private readonly IRepositoryAsync<Product> _repository;   

        public override void Insert(Product entity)
        {
            // e.g. add business logic here before inserting
            base.Insert(entity);
        }

        public override void Delete(object id)
        {
            // e.g. add business logic here before deleting
            base.Delete(id);
        }

        public IEnumerable<Product> GetProductByPermission(string name)
        {
            // add business logic here
            return _repository.GetProductByName(name);
        }     
    }
I also addded those lines to RegisterTypes method in UnityConfig:
                .RegisterType<IRepositoryAsync<Product>, Repository<Product>>()
                .RegisterType<IProductService, ProductService>()
And i receivec error:
'Repository.Pattern.Repositories.IRepositoryAsync<Northwind.Entities.Models.Product>' does not contain a definition for 'GetProductByName' and no extension method 'GetProductByName' accepting a first argument of type 'Repository.Pattern.Repositories.IRepositoryAsync<Northwind.Entities.Models.Product>' could be found (are you missing a using directive or an assembly reference?)
Could you tell me what else i have to do?
Dec 19, 2014 at 7:40 AM
change the line:
public static IEnumerable<Product> GetProductByName(this IRepository<Product> repository, string name)
to:
public static IEnumerable<Product> GetProductByName(this IRepositoryAsync<Product> repository, string name)
Marked as answer by lelong37 on 12/19/2014 at 5:45 PM