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

Naming conventions and specification infrastructure #26

Closed
fiseni opened this issue Jun 30, 2020 · 3 comments
Closed

Naming conventions and specification infrastructure #26

fiseni opened this issue Jun 30, 2020 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@fiseni
Copy link
Collaborator

fiseni commented Jun 30, 2020

People are already quite familiar with LINQ. Why would we introduce new method names for them to remember? Instead of AddCriteria, let just be Where; instead of AddInclude, let be Include, etc. Other than that, usually it's not quite obvious what functionalities the base classes offer, and users constantly look it up to see what's available. Let simply define property which would encapsulate everything. Simply, it can be this. The statements would look better and more familiar to the users. Might be as following

    public abstract class BaseSpecification<T> : ISpecification<T>
    {
        protected BaseSpecification<T> Query { get; }

        protected BaseSpecification()
        {
            Query = this;
        }
    }

// Usage

    public class MySpec : BaseSpecification<MyEntity>
    {
        public MySpec() : base()
        {
            Query.Where(x => x.ID == 1);
            Query.Include(x => x.MyEntityCollection);
        }
    }

Obviously, we don't need extra property Query, the user simply can use this. It's just a matter of what's more visually appealing.

@fiseni
Copy link
Collaborator Author

fiseni commented Jul 2, 2020

I gave a second thought to this. We will utilize a newly created builder which will encapsulate all the methods for creating the specification. So, the Query won't be this, but actually will return a instance of the builder.
I think this will offer much "cleaner" usage, since all the properties that have nothing to do with building the spec are not listed at all.

    public class BlogWithPostsSpec : BaseSpecification<Blog>
    {
        public BlogWithPostsSpec(int id) : base()
        {
            // Query contains only methods for building the spec, which are not available otherwise.
            Query.Where(x => x.Id == id)
                .Include(x => x.Posts)
                .EnableCache(nameof(BlogWithPostsSpec), id)
                .ApplyPaging(10, 20)
                .OrderBy(x => x.Name)
                .ThenByDescending(x => x.Url);
        }
    }

@fiseni fiseni changed the title Naming conventions Naming conventions and specification infrastructure Jul 2, 2020
@ardalis
Copy link
Owner

ardalis commented Jul 13, 2020

I agree with using Builder pattern here.

@ardalis ardalis added this to the 4.0 milestone Jul 13, 2020
@ardalis ardalis added enhancement New feature or request help wanted Extra attention is needed labels Jul 13, 2020
@fiseni
Copy link
Collaborator Author

fiseni commented Jul 17, 2020

This issue is addressed with PR #30
If no one has comments, we may close it.

@fiseni fiseni closed this as completed Aug 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants