---
title: "ASP.NET设计模式读书笔记（3）---FrontController模式"
author: "dotcpp"
date: "2013-06-30T22:58:11Z"
tags: []
categories: ["Web前端"]
slug: "asp-net-3-frontcontroller"
draft: false
lastmod: "2013-06-30T22:58:11Z"
id: 1896333
url: "https://dotcpp.iteye.com/blog/1896333"
---

FrontController将所有的业务功能和配套的基础关注点（比如授权、安全及视图呈现）集中化。

该模式执行流程如下：

 

![](http://dl2.iteye.com/upload/attachment/0086/3268/b5c439aa-8f1d-3148-b66d-9bb81d3aa2f6.jpg)  
   
![](http://dl2.iteye.com/upload/attachment/0086/3270/79b2222c-eef3-33b7-93a3-a6e3a31a19ee.jpg)

 

书中第一种实现方式是以Command（命令模式）实现，主要类结构如下图所示：

![](http://dl2.iteye.com/upload/attachment/0086/3546/24b81f6d-b36a-3425-beab-29ab50779f89.jpg)

最后采用一个CustomHTTPHandler:IHttpHandler来拦截最被的HTTP请求，使其能够正确处理自定义的路径。 如下：

```
public class CustomHTTPHandler : IHttpHandler 
    {        
        public void ProcessRequest(HttpContext context)
        {
            ObjectFactory.GetInstance<FrontController>()
                .handle(ObjectFactory.GetInstance<IWebRequestFactory>().CreateFrom(context));
        }

        public bool IsReusable
        {
            get { return true; }
        }     
    }
```