Comparison of java spring,. net castle windsor, and unity containers

Source: Internet
Author: User

The comprehensive research uses java spring.net castleunity for management. When using the configuration file, we find that java spring and castle windsor are concise, but in terms of service support and RoadMap, we feel that they are in. the net field is still winning by Unity and can be fully utilized. net framework.

  

Reasons for choosing Unity:

1. Continuous RoadMap

2. Powerful Microsoft

3. Because it is Based on. net, it is more primitive.

4. Integration with WCF

 

I. java spring usage:

Import javax. jws. WebService;

Import org. springframework. beans. factory. annotation. Autowired;

Import capinfo. sior. service. OnlineReportPreRegisterService ;;

/**
* @ Author design-life
*/
@ WebService (serviceName = "InfoReportWebService", endpointInterface = "InfoReportWebService", targetNamespace = "http: // reportwbs /")
Public class GetPreRegisterInfoWebServiceImpl {
@ Autowired
OnlineReportPreRegisterService service;
Public String GetPreRegisterInfo (String registerCode, String scanCode ){
Return service. getPreRegisterInfo (registerCode, scanCode );

}
}

 

Note:

OnlineReportPreRegisterService is an Interface defined by @ Autowired to automatically assemble and instantiate a class. The specific definition is encapsulated in an xml, and the Implementation class is represented as a bean in xml.

 

Ii. net Castle usage:

 

Namespace TestService. Controller
{
Using Castle. Core;
Using Castle. DynamicProxy;
[ControllerDetails (Area = "TestService")]
Public class BulletinInfoController: SmartDispatcherController
{
Private readonly IDataQuery query;
Private string _ title;

Public BulletinInfoController (IDataQuery query)
{
This. query = query;
}

Public BulletinInfoController (){}

Public IList <News> List ()
{
IList <News> list;
News news = new News ();

List = query. UseCriteriaAPI_Get2pagelistinfo (news );

Return list;
}

 

}

Note: famous in Castle

Private readonly IDataQuery query; however, the constructor needs to make it available for containers to manage the Controller and Service in the whole Castle.

 

Iii. Unity usage

 

 

Public static void TestCode2 ()
{
Var fileAdd = "unityApp. config ";
Var filePath = new ExeConfigurationFileMap {ExeConfigFilename = fileAdd };

Try
{
Configuration cfg = ConfigurationManager. OpenMappedExeConfiguration (filePath, ConfigurationUserLevel. None );

Var unitySection = (UnityConfigurationSection) cfg. GetSection ("unityTest ");

Var container = new UnityContainer (). LoadConfiguration (unitySection, "one ");
Var iAdd = container. Resolve <IAddInfo. IAddInfo> ();

Console. WriteLine (iAdd. policymsg ());
}
Catch (Exception err)
{
Throw err;
}

Console. ReadKey ();
}

Note: The black text part is the method for Unity to use the configuration file, which is a little troublesome. However, you can extract this part in the same way as the first and second methods.

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.