Implement different concretions to an abstract class that implements a generic service : <p>I have a generic interface and one generic class with generic methods to query the database.</p>

<pre><code>    public interface IRepositoryBase&lt;Entity&gt; {
        IEnumerable&lt;TEntity&gt; GetAll(Func&lt;IQueryable&lt;TEntity&gt;, IncludableQueryable&lt;TEntity, object&gt;&gt; include = null);
    }

    public class RepositoryBase&lt;TEntity&gt; 
        : IDisposable, IRepositoryBase&lt;TEntity&gt;
        where TEntity : class
    {
        public IEnumerable&lt;TEntity&gt; GetAll(Func&lt;IQueryable&lt;TEntity&gt;, IIncludableQueryable&lt;TEntity, object&gt;&gt; include = null)
        {
            IQueryable&lt;TEntity&gt; query = _context.Set&lt;TEntity&gt;();

            if (include != null)
                query = include(query);

            return query.ToList();
        }
    }
</code></pre>

<p>I also have several classes that I call "services" that have the business logic and implement another generic interface.</p>

<pre><code>    public interface IServiceBase&lt;TEntity&gt;
        where TEntity : class
    {
        IEnumerable&lt;TEntity&gt; GetAll(Func&lt;IQueryable&lt;TEntity&gt;, IIncludableQueryable&lt;TEntity, object&gt;&gt; include = null);
    }

    public class ServiceBase&lt;TEntity&gt;
        : IDisposable, IServiceBase&lt;TEntity&gt; 
        where TEntity : class
    {
        private readonly IRepositoryBase&lt;TEntity&gt;
            _repository;

        public ServiceBase(
            IRepositoryBase&lt;TEntity&gt; repository)
        {
            _repository = repository;
        }

        public ServiceBase()
        {
        }

        public IEnumerable&lt;TEntity&gt; GetAll(Func&lt;IQueryable&lt;TEntity&gt;, IIncludableQueryable&lt;TEntity, object&gt;&gt; include = null)
        {
            return _repository.GetAll(include);
        }
    }

    public class PizzaService : ServiceBase&lt;Piza&gt;, IPizzaService
    {
        private readonly IPizzaRepository _pizzaRepository;
        public PizzaService (IPizzaRepository pizzaRepository)
            : base(pizzaRepository)
        {
            _pizzaRepository= pizzaRepository;
        }
    }
</code></pre>

<p>This way each service have their methods acessing their own table plus the methods in the ServiceBase.</p>

<p>There is a scenario where I have 3 concrete services like PizzaService, each one querying its own table, with really similar code, because of the table and the logic similarity.</p>

<p>I want to refactor those concrete services into one, changing only the method param and the repository being acessed, to be in compliance to DRY and ISP.</p>

<p>What I currently have:</p>

<pre><code>    public interface IStopRule
    {
        string DsTerm { get; set; }
        bool ShouldDelete { get; set; }
    }

    public interface IExampleRuleStopWordsBase&lt;TEntity&gt; : IServiceBase&lt;TEntity&gt;
        where TEntity : class
    {

    }

    public abstract class ExampleRuleStopWordsBase
        : ServiceBase&lt;IStopRule&gt;, IExampleRuleStopWordsBase&lt;IStopRule&gt;
    {
        private readonly IRepositoryBase&lt;IStopRule&gt; _repo;

        public ExampleRuleStopWordsBase(IRepositoryBase&lt;IStopRule&gt; repo) 
            : base()
        {
            _repo = repo;
        }

        public virtual string ApplyRule(string input)
        {
            var terms = GetAll();
            foreach (var item in terms)
            {
                string regexPattern = @"\b(" + item.DsTerm + @")\b";
                if (item.ShouldDelete &amp;&amp; Regex.Match(input, regexPattern, RegexOptions.IgnoreCase).Success)
                    input = input.Replace(item.DsTerm, string.Empty);
            }

            input = input.Trim();

            return input;
        }
    }

    public class PizzaService : ExampleRuleStopWordsBase, IImportRule 
    {

        public PizzaService(IRepositoryBase&lt;IStopRule&gt; repo)
            : base(repo)
        {
        }

        public void ApplyRule(Pizza pizza)
        {
            base.ApplyRule(pizza.Name);
        }
    }

    public class PizzaProducerService : ExampleRuleStopWordsBase, IImportRule 
    {

        public PizzaProducerService(IRepositoryBase&lt;IStopRule&gt; repo)
            : base(repo)
        {
        }

        public void ApplyRule(Pizza pizza)
        {
            base.ApplyRule(pizza.Producer.Name);
        }
    }

</code></pre>

<p>But I can't figure it out how to pass to the consturctor of ImportRuleStopWordsBase the right entity to make it use the right repository...</p>

<p>Obs: All interfaces and service implementations reside in Domain layers, whereas the implementation of the repository resides in Infrastructure layer.</p>
