public string AbstractFactoryDependencyInjection(int type)
        {
            var builder = new ContainerBuilder();

            if (type == 1)
            {
                builder.RegisterType <SqlServerFactory>().As <IDbFactory>();
            }
            else
            {
                builder.RegisterType <AccessFactory>().As <IDbFactory>();
            }
            var       container = builder.Build();
            var       dbFactory = container.Resolve <IDbFactory>();
            IUserRepo userRepo  = dbFactory.CreateUserRepo();

            userRepo.Insert(null);
            userRepo.GetUser(0);

            IDepartmentRepo departmentRepo = dbFactory.CreateDepartmentRepo();

            departmentRepo.CreateDepartment(null);

            return("Ok DependencyInjection");
        }
        public string AbstractFactoryReflection(string dbName)
        {
            IUserRepo userRepo = DataAccess.CreateUserRepo(dbName);

            userRepo.Insert(null);
            IDepartmentRepo departmentRepo = DataAccess.CreateDepartmentRepo(dbName);

            departmentRepo.CreateDepartment(null);
            return("Ok Reflection");
        }
Beispiel #3
0
 public ActionResult <Department> CreateDepartment(Department createDepartment)
 {
     _repository.CreateDepartment(createDepartment);
     _repository.SaveChanges();
     return(createDepartment);
 }