コード例 #1
0
        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();
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 // inject services through controller's constructor
 public EmployeeProfileController(IHostingEnvironment env, EmployeeProfileDbContext context)
 {
     _env     = env;
     _context = context;
 }
コード例 #4
0
 // inject services through controller's constructor
 public EmployeeProfileController(IHostingEnvironment env, EmployeeProfileDbContext context, FaceApiHelper faceApiHelper)
 {
     _env           = env;
     _context       = context;
     _faceApiHelper = faceApiHelper;
 }