public static void Initialize(IServiceProvider serviceProvider) { using (var context = new HelloHomesPersonContext( serviceProvider.GetRequiredService <DbContextOptions <HelloHomesPersonContext> >())) { // Look for any Persons. if (context.Person.Any()) { return; // DB has been seeded } context.Person.AddRange( new Person { IsAdmin = true, EmailAddress = "*****@*****.**", Password = PersonService.Hash("admin"), FullName = "Admin Bob", PhoneNumber = "0999" }, new Person { IsAdmin = false, EmailAddress = "*****@*****.**", Password = PersonService.Hash("admin"), FullName = "Jim Bob", PhoneNumber = "121313" } ); context.SaveChanges(); } }
public PersonService() { var connString = Startup.personConnString; var options = new DbContextOptionsBuilder <HelloHomesPersonContext>() .UseSqlServer(connString) .Options; _context = new HelloHomesPersonContext(options); }
public PersonService(HelloHomesPersonContext context) { _context = context; }