Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Default Interface Methods #136

Open
tb-mtg opened this issue Jul 22, 2024 · 1 comment
Open

Use Default Interface Methods #136

tb-mtg opened this issue Jul 22, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@tb-mtg
Copy link

tb-mtg commented Jul 22, 2024

Just as suggestion, have you considered moving repeated implementation logic code into their interfaces by taking advantage of default interface methods?

For example, the following overrides could be removed from:
https://github.com/RCommon-Team/RCommon/blob/main/Src/RCommon.Linq2Db/Crud/Linq2DbRepository.cs

public override IQueryable<TEntity> FindQuery(ISpecification<TEntity> specification)  
{
  ... // Logic moved into ILinqRepository.cs
}

public async override Task<IPaginatedList<TEntity>> FindAsync(IPagedSpecification<TEntity> specification, CancellationToken token = default)
{
  ... // Logic moved into ILinqRepository.cs
}

and moved into:
https://github.com/RCommon-Team/RCommon/blob/main/Src/RCommon.Persistence/Crud/ILinqRepository.cs

public interface ILinqRepository<TEntity> : IQueryable<TEntity>, IReadOnlyRepository<TEntity>, IWriteOnlyRepository<TEntity>, 
  IEagerLoadableQueryable<TEntity> 
  where TEntity : IBusinessEntity 
{
  ...
  IQueryable<TEntity> FindQuery(ISpecification<TEntity> specification) 
    => FindQuery(specification.Predicate);


  Task<IPaginatedList<TEntity>> FindAsync(IPagedSpecification<TEntity> specification, CancellationToken token = default) 
    => FindAsync(specification.Predicate, specification.OrderByExpression, specification.OrderByAscending, specification.PageIndex, specification.PageSize, token);

  ...
}

@JasonMWebb
Copy link
Collaborator

That is a nice language feature. I'm pretty close to finishing the hardening of version 2.0 and then am quickly moving on to version 2.0.1 where we'll need to begin changing the interfaces in this area. It may be a nice time to look at cleaning up the code a bit with something like default interface methods. Nice recommendation!

@jasonmwebb-lv jasonmwebb-lv added the enhancement New feature or request label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants