title: Using ApplicationUser in a Generic Repository pattern
body: <p>Is it possible to use asp net core's default authentication in a generic repository pattern and if so, how?</p>
  
  <p>I am able to create a project that uses a generic repository pattern for all of my code, except the authentication side of the project which uses the default way.</p>
  
  <p>My repository looks like:</p>
  
  <pre><code>using System.Linq;
  using DemoWebsite.Interfaces;
  using Microsoft.EntityFrameworkCore;
  
  namespace DemoWebsite.Data
  {
   public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T : class
  {
      protected readonly DbContext Context;
      protected DbSet&lt;T&gt; DbSet;
  
      public Repository(ApplicationDbContext context)
      {
          Context = context;
          DbSet = context.Set&lt;T&gt;();
      }
  
      public void Add(T entity)
      {
          Context.Set&lt;T&gt;().Add(entity);
  
          Save();
      }
  
      public T Get&lt;TKey&gt;(TKey id)
      {
          return DbSet.Find(id);
      }
  
      public IQueryable&lt;T&gt; GetAll()
      {
          return DbSet;
      }
  
      public void Update(T entity)
      {
          Save();
      }
  
      private void Save()
      {
          Context.SaveChanges();
      }
  }
  }
  </code></pre>
  
  <p>My ApplicationDbContext class:</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options)
          : base(options)
      {
      }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
          // Customize the ASP.NET Identity model and override the defaults if needed.
          // For example, you can rename the ASP.NET Identity table names and more.
          // Add your customizations after calling base.OnModelCreating(builder);
      }
  }
  </code></pre>