Integrate the wcf intermediate code generated by thrift0.9.2 with Spring. Services-complicated architecture brings simple code and high maintainability, spring. serviceswcf

Source: Internet
Author: User

Integrate the wcf intermediate code generated by thrift0.9.2 with Spring. Services-complicated architecture brings simple code and high maintainability, spring. serviceswcf

I have been reading articles about thrift recently, and most of the content involved is superficial. Once you need to use the actual project, you will encounter various problems!

For example, thrift server-side carrier selection, intermediate code generation options (async asyncctp wcf, etc) to select the basic framework of the server and client, and the ioc architecture that combines the bearer layers.

In fact, there are still a lot of such things. After reading this article, you may need to popularize thrift basics to understand thrift, as well as windowsservices, wcf, and spring.net!

Here, I use C # As the server and customer. Of course, the interface client published by the server doesn't care what language you are. You only need the thrift compiler to generate the corresponding intermediate code and then write the code accordingly.

The code structure I selected is as follows:

I chose windows services as the server carrier, and the compiler must use the latest thrift0.9.2 (I chose wcf when the code is generated). As for the basic framework of Thrift, I chose. net Thrift and Thrift. server and Thrift. client (the Client can support the configuration of multiple server terminals, which is what I am looking for), Ioc framework, in fact, there are many ready-made injection frameworks, what autoface, unity, spring.net, and so on; in fact, we must be clear about the purpose of choosing these dependency injection: (my point of view) making our architecture loose, code more beautiful, less code, high reusability, and easier maintenance. In fact, no matter what the choice is, the purpose of your choice is clear at a glance. Here, my choice must be spring.net, because it supports Spring. Services for Wcf, webservice, windowsservice, and remoting. In addition, there are too many reasons, which allow us to save a lot of code to make the originally bloated Wcf code clear, and it also unifies the dependency injection of all projects.

The Code Generation Command of thrift is: thrift-gen csharp: wcf *. thrift

No spring content can be seen yet. Its role should be to combine the loose code into a final product. Therefore, many spring configurations are involved. In addition, it can only be seen in the app. config of the ServerHost project.

Of course, there are quite a few codes in it, because spring. services is integrated and encapsulated once, the code in ServerHost does not need to be changed. The only thing you need to do is how to use each moduleConfigurationIntegrated.

From the current structure, it seems very simple. In fact, it is not necessary to really integrate them together to do a lot of configuration and debugging work.

Let's take a look at the generated dll file:

This is only a dll file, and I believe anyone who has used spring knows it. Spring brings the gospel in code and structure, but writing configuration files and debugging and integration of the entire framework are a headache.

However, with the open source of. net, the requirements for project architecture, scalability, distribution, and maintainability are also gradually reflected.

So do. net students, don't just see. to achieve this goal, we must pay attention to the middleware developed by various third parties, whether its prototype is developed in java, php, or other languages. The most important thing is that it can bring us what we want. It can make our programs not difficult to maintain, so that the system can grow gradually like a baby, rather than replacing other languages or repeated development.

Related Article

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.