如果在構建DefaultControllerFactory的時候沒有顯式指定采用ControllerActivator
private class DefaultControllerActivator : IControllerActivator
{
public DefaultControllerActivator()
public DefaultControllerActivator(IDependencyResolver resolver)
public IController Create(RequestContext requestContext
Type controllerType)
}
即使DefaultControllerFactory采用了默認的DefaultControllerActivator
其實DefaultControllerActivator完成對Controller的激活依賴於另一個名為DependencyResolver的對象
public interface IDependencyResolver
{
object GetService(Type serviceType)
IEnumerable<object> GetServices(Type serviceType)
}
整個Web默認使用的DependencyResolver可以通過System
public class DependencyResolver
{
//其他成員
private static DependencyResolver _instance;
public void InnerSetResolver(object commonServiceLocator)
public void InnerSetResolver(IDependencyResolver resolver)
public void InnerSetResolver(Func<Type
Func<Type
public static void SetResolver(object commonServiceLocator)
public static void SetResolver(IDependencyResolver resolver)
public static void SetResolver(Func<Type
Func<Type
public static IDependencyResolver Current { get; }
public IDependencyResolver InnerCurrent { get; }
}
這個被封裝的DependencyResolver(指實現了接口IDependencyResolver的某個類型的對象
[
From:http://tw.wingwit.com/Article/program/net/201311/16065.html