Closed amcasey closed 11 months ago
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
API Review Notes:
IDataProtectionKeyContext
.
IDataProtectionKeyContext
implementations that have the setter, but aren't rebuilt with this change.
DbSet<DataProtectionKey> DataProtectionKeys { get; } = new MyDbSet<DataProtectionKey>();
@ajcvickers @csharpfritz Do you have any opinions?
As of now, we think that we should probably go with an analyzer if anything.
From an EF perspective, the DbSet
property does not need to be, and ideally should not be, settable.
From an EF perspective, the
DbSet
property does not need to be, and ideally should not be, settable.
That's interesting... how do you work with the collection if the DbSet is not settable?
This syntax is invalid because DbSet is abstract:
public DbSet<DataProtectionKey> DataProtectionKeys { get; } = new DbSet<DataProtectionKey>();
We can initialize the property in the constructor with syntax like:
DataProtectionKeys = Set<DataProtectionKey>();
Either way... we can agree that the auto-generated syntax is invalid. I think I'd favor an analyzer that throws an error on this misconfiguration.
@csharpfritz My personal favorite pattern is:
public DbSet<DataProtectionKey> DataProtectionKeys => Set<DataProtectionKey>();
You can provide a public or private setter, and then EF will initialize the properties for you. Or you can call Set
in the constructor and initialize the properties explicitly there.
The main point here is that consumers will never call the setter, so my preference is to not include it, and certainly it should not be required by the interface.
API rejected. Thanks, @ajcvickers!
Background and Motivation
I understand that it's required when persisting keys to EF, so we should reflect that in the interface. Note that it's included in our docs.
PR: https://github.com/dotnet/aspnetcore/pull/52644
Proposed API
Usage Examples
Alternative Designs
It might be possible to use a default interface member that throws, but I wouldn't guess you could add a single accessor to an existing property.
Risks
Obviously, it's a breaking change. I understand it only breaks people who are already persisting keys incorrectly.