protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            IProductRepository productRepository = new ProductRepository();
            var productService = new ProductService(productRepository);

            if (controllerType == (typeof(HomeController)))
            {
                return new HomeController(productService);
            }

            if (controllerType == (typeof(ProductController)))
            {
                return new ProductController(productService);
            }
            return base.GetControllerInstance(requestContext, controllerType);
        }
コード例 #2
0
        //
        // GET: /Default/
        public ActionResult Index()
        {
            var productRepository = new ProductRepository();
            var productService = new ProductService(productRepository);

            var products = productService.GetProductsOnSale();

            var vm = new HomePageViewModel();
            vm.Products = new List<ViewModelProduct>();

            foreach (var product in products)
            {
                vm.Products.Add(new ViewModelProduct(product.Id, product.Name));
            }
            return View(vm);
        }