Controller與ContrllerFactory
我們為Controller定義了一個接口Icontroller
public interface IController
{
void Execute(RequestContext requestContext)
}
從MvcHandler的定義可以看到Controller對象的激活是通過工廠模式實現的
public interface IControllerFactory
{
IController CreateController(RequestContext requestContext
string controllerName)
}
在MvcHandler的ProcessRequest方法中
ControllerBuilder的整個定義如下面的代碼片段所示
public class ControllerBuilder
{
private Func<IControllerFactory> factoryThunk;
public static ControllerBuilder Current { get; private set; }
static ControllerBuilder()
{
Current = new ControllerBuilder()
}
public IControllerFactory GetControllerFactory()
{
return factoryThunk()
}
public void SetControllerFactory(IControllerFactory controllerFactory)
{
factoryThunk = () => controllerFactory;
}
}
再回頭看看之前建立在自定義ASP
[
From:http://tw.wingwit.com/Article/program/net/201311/16108.html