Controller activation Understanding for ASP.

Source: Internet
Author: User

Defaultcontrollerfactory is the default controller for MVC to find and activate factory classes
We can implement the IOC introduction by customizing the Controllerfactory to replace the Defaultcontrollerfactory class.

public class Defaultcontrollerfactory:icontrollerfactory
{
Other Members
public Defaultcontrollerfactory ();
Public defaultcontrollerfactory (Icontrolleractivator controlleractivator);

}
Public interface Icontrolleractivator//controller Activator interface
{
IController Create (RequestContext requestcontext, Type controllertype);
}

This class is a private inner class of defaultcontrollerfactory, which is called when the default constructor of Defaultcontrollerfactory or the Icontrolleractivator parameter is null. This inner class is used by default to activate the controller
Private Class Defaultcontrolleractivator:icontrolleractivator
{
Private func<idependencyresolver> _resolverthunk; used to return an instance of the Idependencyresolver implementation class
public Defaultcontrolleractivator ();
Public Defaultcontrolleractivator (Idependencyresolver resolver);
Public IController Create (RequestContext requestcontext, Type controllertype);
}

Used to get the controller object.
public interface Idependencyresolver
{
Object GetService (Type servicetype);
Ienumerable<object> getservices (Type servicetype);
}

This class is used to encapsulate the implementation class that manages the Idependencyresolver class.
public class Dependencyresolver
{
private static Dependencyresolver _instance;
public void Innersetresolver (object commonservicelocator);
public void Innersetresolver (Idependencyresolver resolver);
public void Innersetresolver (Func<type, object> getService, Func<type, ienumerable<object>> GetServices);
public static void Setresolver (object commonservicelocator);
public static void Setresolver (Idependencyresolver resolver);
public static void Setresolver (Func<type, object> getService, Func<type, ienumerable<object>> GetServices);
public static idependencyresolver current {get;}
Public Idependencyresolver innercurrent {get;}
}
Class diagrams (Pictures are referenced fromJing JinnanTeacher's blog):



Summary: Instantiates the Defaultcontrollerfactory class if the icontrolleractivator parameter equals null or there is no incoming parameter. The Defaultcontrollerfactory class creates an instance of the internal private Icontrolleractivator Interface implementation Class (Defaultcontrolleractivator)

Used to activate the Controller class, and the Defaultcontrolleractivator class will first determine if the internal private delegate resolverthunk is empty. If empty, returns an instance of the Idependencyresolver implementation class under the Dependencyresolver.current static property, which is used to actually create the activation

Controller class; Execute this delegate to obtain an instance of the Idependencyresolver implementation class to activate the controller. (MVC defaults to activating the controller by reflection)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.