public static void Initialize(IServiceProvider serviceProvider) { using (var context = new EmployeeProfileDbContext( serviceProvider.GetRequiredService <DbContextOptions <EmployeeProfileDbContext> >())) { // Look for any movies. if (context.EmployeeProfiles.Any()) { return; // DB has been seeded } context.EmployeeProfiles.AddRange( new EmployeeProfile { FirstName = "Armen", LastName = "Romo", Title = "Software Engineer", Department = "Engineering" }, new EmployeeProfile { FirstName = "Corinne", LastName = "Horn", Title = "Business Analyst", Department = "Human Resources" }, new EmployeeProfile { FirstName = "Dan", LastName = "Drayton", Title = "System Administrator", Department = "IT" }, new EmployeeProfile { FirstName = "Joann", LastName = "Chambers", Title = "Senior Accoutant", Department = "Finance" } ); context.SaveChanges(); } }
private void Initialize() { // Create InMemory Database for testing var options = new DbContextOptionsBuilder <EmployeeProfileDbContext>() .UseInMemoryDatabase(databaseName: "EmployeeProfileDb") .Options; var context = new EmployeeProfileDbContext(options); // Seed data SeedEmployeeProfiles.Initialize(context); // Create the repository _repository = new EmployeeProfileRepository(context); // create the controller _controller = new EmployeeProfileController(new HostingEnvironment(), _repository); }
// inject services through controller's constructor public EmployeeProfileController(IHostingEnvironment env, EmployeeProfileDbContext context) { _env = env; _context = context; }
// inject services through controller's constructor public EmployeeProfileController(IHostingEnvironment env, EmployeeProfileDbContext context, FaceApiHelper faceApiHelper) { _env = env; _context = context; _faceApiHelper = faceApiHelper; }