1. Introduction of DLLs
Common.Logging.dllSpring.Core.dllSpring.Web.dllSpring.Web.Extensions.dllSpring.Web.Mvc4.dll
2. Copy the Config folder in the case to this project.
Copy the Examples>spring>spring.mvc4quickstart>spring.mvc4quickstart>config folder into the project
3. Modify the relevant configuration in config folder
Open Config folder in the Controllers.xml file can see the file is in the previous article said objects
<?XML version= "1.0" encoding= "Utf-8"?><Objectsxmlns= "Http://www.springframework.net"> <Objecttype= "Spring.Mvc4QuickStart.Controllers.HomeController, Spring.mvc4quickstart"Singleton= "false" > < Propertyname= "Message"value= "Welcome to ASP. MVC4 Powered by spring.net!" /> </Object> <Objecttype= "Spring.Mvc4QuickStart.Controllers.SuffixController, Spring.mvc4quickstart"Singleton= "false" > < Propertyname= "Suffix"value= "_spring.net_was_here!" /> </Object> <Objecttype= "Spring.Mvc4QuickStart.Controllers.OdataController, Spring.mvc4quickstart"Singleton= "false" /> <!--intentionally don't register the AccountController or the valuescontroller with the container; demonstrates the Underlying default controller factory would properly (attempt to!) resolve all controllers no registered with Spring.net Using its default controller resolution Behavoir - <!--<object type= "Spring.Mvc4QuickStart.Controllers.AccountController, Spring.mvc4quickstart" singleton= "false "/> - <!--<object type= "Spring.Mvc4QuickStart.Controllers.ValuesController, Spring.mvc4quickstart" singleton= "false" /> -</Objects>
In the <object> node is the class instance, the controller is also a class,<property> in the class of properties, controller how to attribute it?
When a class in the BLL is called in the controller, it is:
New Bll. Oa_userinfoservice ();
Rewritten as:
Ibll. Ioa_userinfoservice userinfoservice{get; Set;}
This can turn userinfoservice into a property.
Where Oa_userinfoservice is also a class,<object>, it becomes:
<!--type= "namespace full name, assembly name - <Objecttype= "Bzindexoa.webui.controllers.userinfocontroller,bzindexoa.webui"Singleton= "false" > < Propertyname= "Userinfoservice"ref= "Oa_userinfoservice" /> </Object> <Objectname= "Oa_userinfoservice"type= "BZINDEXOA.BLL.OA_USERINFOSERVICE,BZINDEXOA.BLL"Singleton= "false" > </Object>
4. Modifying configuration information in the Web. config
Add the <configSections> in the <configuration> node
<name= "Spring"><!-- spring.net configuration -- <name= "context" type= " Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc4 "/> </ Sectiongroup>
Then add in the <configuration> node
<Spring><!--spring.net Configuration - <Context> <ResourceURI= "File://~/Config/controllers.xml"/> </Context> </Spring> <!--spring.net Configuration End -
The configuration information is as follows:
Now the spring has been completed. NET is configured in MVC
// IBLL. Ioa_userinfoservice userinfoservice = new BLL. Oa_userinfoservice (); Ibll. Ioa_userinfoservice userinfoservice{get; Set;}
The above code can be used in place of the comment section and run normally.
5. You can detach the configuration information from the Config/controllers.xml file (separating the configuration of the controller from the configuration of the business Class)
Create a new Services.xml file in the Config folder to add content:
<?XML version= "1.0" encoding= "Utf-8"?><Objectsxmlns= "Http://www.springframework.net"> <!--type= "namespace full name, assembly name - <Objectname= "Oa_userinfoservice"type= "BZINDEXOA.BLL.OA_USERINFOSERVICE,BZINDEXOA.BLL"Singleton= "false" > </Object></Objects>
Then put the <object in the Controllers.xml file name= "Oa_userinfoservice" type= "BZINDEXOA.BLL.OA_USERINFOSERVICE,BZINDEXOA.BLL" Singleton= "false" > Delete.
The configuration file is then added to the context node of Web. config and becomes:
< Context > < uri= "File://~/Config/controllers.xml"/> < URI = "File://~/Config/services.xml" /> </ Context >
In this case, the configuration of the controller is in Controllers.xml, which is the configuration in the business class.
When the configuration is complete, run the program to see the effect.
Spring. NET IOC's use in MVC