-
Notifications
You must be signed in to change notification settings - Fork 87
Merge the EF Core provider for storing keys #323
Conversation
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.
Looks a'ight to me. The actual product code is fairly concise.
@ajcvickers / @divega - would you like an EF expert to review the EF parts of this feature?
It's a fairly small amount of actual EF-ness. |
Docs PR: dotnet/AspNetCore.Docs#8328. |
{ | ||
using (var scoped = services.GetRequiredService<IServiceScopeFactory>().CreateScope()) | ||
{ | ||
return scoped.ServiceProvider.GetRequiredService<T>(); |
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.
Wouldn't this return the DbContext instance and then immediately after dispose it by disposing the DI scope that contains it? Perhaps I am missing something or forgetting something about how DI works.
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.
Good catch. I've cleaned this up.
🆙 📅 |
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace EntityFrameworkCore |
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.
Is this a sample on how to use it or something else? Should it really be in the EntityFrameworkCore namespace?
/// The entity identifier of the <see cref="DataProtectionKey"/>. | ||
/// </summary> | ||
[Key] | ||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] |
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.
int Id
property will be mapped as "identity" key by convention, so these attributes are not needed by EF.
public virtual IReadOnlyCollection<XElement> GetAllElements() | ||
{ | ||
using (var scope = _services.CreateScope()) | ||
using (var context = scope.ServiceProvider.GetRequiredService<TContext>()) |
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.
Disposing the scope should dispose the context. It's unusual and should not be necessary to dispose it explicitly, but I don't think it will do any harm.
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.
Added some minor comments, but looks good to me.
Cool beans. I'm going to cleanup per @ajcvickers's comments and merge. |
da2bb71
to
71e5a99
Compare
…ge version to 2.2
71e5a99
to
7520ffa
Compare
FYI @blowdart
TODO:
* Docsdotnet/AspNetCore.Docs#8328* Update Universe to make this package shippingaspnet/Universe#1349Resolves dotnet/aspnetcore#2505