-
Notifications
You must be signed in to change notification settings - Fork 246
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
397 make fields and methods protected #398
397 make fields and methods protected #398
Conversation
@@ -10,8 +10,8 @@ namespace Ardalis.Specification.EntityFramework6; | |||
/// <inheritdoc/> | |||
public abstract class RepositoryBase<T> : IRepositoryBase<T> where T : class | |||
{ | |||
private readonly DbContext _dbContext; | |||
private readonly ISpecificationEvaluator _specificationEvaluator; | |||
protected readonly DbContext _dbContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a property
protected DbContext { get; private set; }
combined with
public RepositoryBase(DbContext dbContext)
{
DbContext = dbContext;
}
is more appropriate then a protected member.
The same for SpecificationEvaluator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to change too much, but I see your point. If we let subclasses access these "fields" it will be safer to do "props" instead from a maintenance perspective. I've made that change and pushed
If you use a property with |
For my needs, I only needed to override the methods while still being able to refer to and read the fields (now props) from the subclass. I don't need to mess with the constructor signatures or replace/modify the state. Only the behaviour. So for me, this is enough. I can see a case for opening it up further. If you believe this is the way to go, I'll happily remove the |
I'm not clear on what the benefits of the property are over the field, in this case. The field change (as originally done in this PR) seems simpler and provides greater extensibility. The property adds additional encapsulation, but I'm not sure that's needed or desirable in this case. However, I recognize I'm not the target audience for this change, so if y'all are ok with it as is I think we can merge it. Let me know. |
This affords maximum extensibility, while still encapsulating the values within a property
In that case, let's opt for maximum extensibility with maximum encapsulation. Most power and most safety. I've removed the |
TL;DR: Holy 💩, I didn't mean to start such a conversation about a property 🤣... Any solution allowing te behavior described here is fine for me. Longer version As per @ardalis observations about extensibility, I opened #397 mostly because I needed a way to "override" the auto-save behavior in the methods and therefore, as @eldamir correctly pointed out, you need to access the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment here ⬆️
I think we landed in the best spot here. No "field inheritance", and properties are available for read and write as needed by inheritors with proper encapsulation. I'd be happy to see this merged 😉 |
Now I just need to release it... |
Just what I needed!! Waiting the release |
Fixes #397