Pro ASP.NET MVC Framework phần 3

Trên lý thuyết, mô hình này sẽ giúp những web designer chủ động thiết kế ra giao diện của ứng dụng mà không sợ ảnh hưởng đến những phần code xử lý bên dưới. Điều này dường như giống với ý tưởng tách rời giữa controller và view trong mô hình Model-View-Controller framework. | CHAPTER 4 SPORTSSTORE A REAL APPLICATION 99 configSections section name castle type -- . leave all the other section nodes as before . -- configSections Then directly inside the configuration node add a castle node configuration -- etc -- castle components components castle -- etc -- You can put the castle node immediately before . Finally instruct ASRNET MVC to use your new controller factory by calling SetControllerFactory inside the Application_Start handler in protected void Application_Start RegisterRoutes new WindsorControllerFactory At this point it s a good idea to check that everything still works as before when you run your application. Your new IoC container should be able to resolve ProductsController when ASRNET MVC requests it so the application should behave as if nothing s different. Using Your loC Container The whole point of bringing in an IoC container is that you can use it to eliminate hard-coded dependencies between components. Right now you re going to eliminate ProductsController s current hard-coded dependency on SqlProductsRepository which in turn means you ll eliminate the hard-coded connection string soon to be configured elsewhere . The advantages will soon become clear. When an IoC container instantiates an object . a controller class it inspects that type s list of constructor parameters . dependencies and tries to supply a suitable object for each one. So if you edit ProductsController adding a new constructor parameter as follows public class ProductsController Controller private IProductsRepository productsRepository public ProductsController IProductsRepository productsRepository productsRepository 100 CHAPTER 4 SPORTSSTORE A REAL APPLICATION public ViewResult List return View then the loC .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
1    278    3    29-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.