Skip to content
This repository was archived by the owner on Oct 17, 2018. It is now read-only.

Merge the EF Core provider for storing keys #323

Merged
merged 2 commits into from
Aug 30, 2018

Conversation

natemcmaster
Copy link
Contributor

@natemcmaster natemcmaster commented Aug 29, 2018

FYI @blowdart

TODO:
* Docs dotnet/AspNetCore.Docs#8328
* Update Universe to make this package shipping aspnet/Universe#1349

Resolves dotnet/aspnetcore#2505

@natemcmaster natemcmaster requested a review from blowdart August 29, 2018 21:46
Copy link
Member

@Eilon Eilon left a 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.

@Eilon
Copy link
Member

Eilon commented Aug 29, 2018

@natemcmaster
Copy link
Contributor Author

Docs PR: dotnet/AspNetCore.Docs#8328.

{
using (var scoped = services.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
return scoped.ServiceProvider.GetRequiredService<T>();
Copy link

@divega divega Aug 30, 2018

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.

Copy link
Contributor Author

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.

@natemcmaster
Copy link
Contributor Author

🆙 📅

@natemcmaster natemcmaster requested a review from divega August 30, 2018 03:01
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace EntityFrameworkCore

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)]

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>())

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.

Copy link

@ajcvickers ajcvickers left a 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.

@natemcmaster
Copy link
Contributor Author

Cool beans. I'm going to cleanup per @ajcvickers's comments and merge.

@natemcmaster natemcmaster force-pushed the feature/efcore-provider branch from da2bb71 to 71e5a99 Compare August 30, 2018 23:20
@natemcmaster natemcmaster force-pushed the feature/efcore-provider branch from 71e5a99 to 7520ffa Compare August 30, 2018 23:24
@natemcmaster natemcmaster merged commit 7520ffa into release/2.2 Aug 30, 2018
@natemcmaster natemcmaster deleted the feature/efcore-provider branch August 30, 2018 23:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants