public UserRepository(UserManager <ApplicationUser> userManager, BlogHostingDbContext context, SignInManager <ApplicationUser> signInManager) { _userManager = userManager; _context = context; _signInManager = signInManager; }
static void Main(string[] args) { var services = new ServiceCollection(); ConfigureServices(services); serviceProvider = services.BuildServiceProvider(); var optionsBuilder = new DbContextOptionsBuilder <BlogHostingDbContext>(); optionsBuilder .UseLazyLoadingProxies() .UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=aspnet-BlogHosting-123BCBEF-17A2-4F0F-8B69-F13F4F2ADE44;Trusted_Connection=True;MultipleActiveResultSets=true"); //var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>(); var signInManager = serviceProvider.GetRequiredService <SignInManager <DAL.Interface.DTO.ApplicationUser> >(); using (var context = new BlogHostingDbContext(optionsBuilder.Options)) { var rep = new UserRepository(serviceProvider.GetRequiredService <UserManager <DAL.Interface.DTO.ApplicationUser> >(), context, signInManager); var service = new AuthenticateService(rep); //var user = service.GetUserByUsernamee("User1"); //Console.WriteLine(user.FirstName); } }
public static void DetachLocal <T>(this BlogHostingDbContext context, T t, int entryId) where T : class { var local = context.Set <T>() .Local .FirstOrDefault(entry => entry.GetType().GetProperties() .Single(p => p.Name.EndsWith("Id")) .GetValue(entry).Equals(entryId)); if (local != null) { context.Entry(local).State = EntityState.Detached; } context.Entry(t).State = EntityState.Modified; }
public BlogRepository(BlogHostingDbContext context) { _context = context; }