Java spring \. net castle \ unity for management. When using the configuration file, we found that java spring and castle windsor are concise, but in terms of service support and RoadMap, we think that 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@ Autowired indicates that a class is automatically assembled and instantiated. The specific definition is encapsulated in an xml file, 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.