In the above, describes how to install and use Suteki, today we use the source to see how Suteki is using controller.
In Suteki, it uses the abstract method to define a controllerbase as the base class for all controller, and the following is a class diagram of its controller:
Some methods commonly used in controller are defined in the base class, such as adding metadescription,title to the current view:
[Rescue ("Default"), Authenticate, Copymessagefromtempdatatoviewdata]
Public abstract class Controllerbase:controller, Iprovidesbaseservice
{
Private Ibasecontrollerservice Basecontrollerservice;
<summary>
Supplies services and configuration to all controllers
</summary>
Public Ibasecontrollerservice Basecontrollerservice
{
get {return basecontrollerservice;}
Set
{
Basecontrollerservice = value;
viewdata["Title"] = "{0}{1}". With (
Basecontrollerservice.shopname,
Getcontrollername ());
viewdata["metadescription"] = "\" {0}\ "". With (basecontrollerservice.metadescription);
}
}
Public ILogger Logger {get; set;}
Public virtual string Getcontrollername ()
{
Return "-{0}". With (GetType (). Name.replace ("Controller", ""));
}
public virtual void Appendtitle (string text)
{
ViewData ["Title"] = "{0}-{1}". With (viewdata["Title"], text);
}
public virtual void Appendmetadescription (string text)
{
ViewData ["metadescription"] = text;
}
public string Message
{
get {return tempdata[' message ' As String;}
set {TempData ["message"] = value;}
}
protected override void Onexception (Exceptioncontext filtercontext) {
Response.Clear ();
Base. Onexception (Filtercontext);
}
}
Of course, a careful friend found that the abstract class also includes an instance of the Ibasecontrollerservice interface.
The interface of the main definition of some online shop system information, such as shop name, copyright information, email information, as follows:
public interface IBaseControllerService
{
IRepository<Category> CategoryRepository { get; }
string GoogleTrackingCode { get; set; }
string ShopName { get; set; }
string EmailAddress { get; set; }
string SiteUrl { get; }
string MetaDescription { get; set; }
string Copyright { get; set; }
string PhoneNumber { get; set; }
string SiteCss { get; set; }
}
The subclass "Basecontrollerservice", which implements the interface as the only one, is defined as follows:
public class BaseControllerService : IBaseControllerService
{
public IRepository<Category> CategoryRepository { get; private set; }
public string GoogleTrackingCode { get; set; }
public string MetaDescription { get; set; }
private string shopName;
private string emailAddress;
private string copyright;
private string phoneNumber;
private string siteCss;
..
}