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

Update the infrastructure for single result specifications. #272

Merged
merged 5 commits into from
Jun 23, 2022

Conversation

fiseni
Copy link
Collaborator

@fiseni fiseni commented Jun 18, 2022

Closes #242. Refer to the related issue for more details.

  • Added the ISingleResultSpecification<T, TResult> interface.
  public interface ISingleResultSpecification
  {
  }
  public interface ISingleResultSpecification<T> : ISpecification<T>, ISingleResultSpecification
  {
  }
  public interface ISingleResultSpecification<T, TResult> : ISpecification<T, TResult>, ISingleResultSpecification
  {
  }
  • Added the SingleResultSpecification base classes for convenience.
  public class SingleResultSpecification<T> : Specification<T>, ISingleResultSpecification<T>
  {
  }
  public class SingleResultSpecification<T, TResult> : Specification<T, TResult>, ISingleResultSpecification<T, TResult>
  {
  }
  • Removed the constraints for GetBySpec repository method. Marked these methods as obsolete.
  [Obsolete]
  Task<T?> GetBySpecAsync(ISpecification<T> specification, CancellationToken cancellationToken = default);

  [Obsolete]
  Task<TResult?> GetBySpecAsync<TResult>(ISpecification<T, TResult> specification, CancellationToken cancellationToken = default);
  • Added verbose repository methods.
  // These will work with any specification.
  Task<T?> FirstOrDefaultAsync(ISpecification<T> specification, CancellationToken cancellationToken = default);
  Task<TResult?> FirstOrDefaultAsync<TResult>(ISpecification<T, TResult> specification, CancellationToken cancellationToken = default);

  // These will work only with SingleResultSpecification 
  Task<T?> SingleOrDefaultAsync(ISingleResultSpecification<T> specification, CancellationToken cancellationToken = default);
  Task<TResult?> SingleOrDefaultAsync<TResult>(ISingleResultSpecification<T, TResult> specification, CancellationToken cancellationToken = default);
  • Added UpdateRangeAsync repository method (community request).
  Task UpdateRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default);

@fiseni fiseni requested a review from ardalis June 21, 2022 20:24
@ardalis
Copy link
Owner

ardalis commented Jun 23, 2022

Looks great!

@davidhenley
Copy link
Contributor

Does this mean GetBySpecAsync should be replaced with First/SingleOrDefaultAsync?

Just making sure as it's not stated anywhere in the release notes

@ardalis
Copy link
Owner

ardalis commented Aug 2, 2022

Yes, and I'll try and get the release notes updated.

@fiseni fiseni deleted the single-result-specification branch July 24, 2023 16:23
fiseni referenced this pull request Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ISingleResultSpecification usage issue.
3 participants