In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to build a Web framework based on the .NET platform, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know it.
one。 Technical analysis
1.web data transmission
ExtJS as the front-end UI presentation layer, the transmission data format is Json or xml, generally most of them are Json.
2.ASP.NET MVC
(don't think too much about other features of mvc, controller+method is enough.) and routing url meets this requirement well and is easy to implement.
3. Choose a dependency injection container
As long as you have learned an Ioc component, the concept is still the same, but the approach is different. I chose Microsoft Unity.
Here I do not configure Service in xml, according to my understanding, most software does not need to be so flexible, I just register (in fact, this is often the case, we can ask ourselves how many features we use). Because most of them are registered once and will never be modified. You can bring it up when it's really necessary.
There are many Ioc components, I think the more powerful is spring.net, the function is very rich, there are AOP functions, the most important thing is that it can be well combined with other components.
Container, as an underlying service, is mainly to provide us with flexibility. Find ways to combine with existing components and register related services.
4. Database operation (NHibernate)
I would have chosen ADO.NET three years ago.
I chose Microsoft.Practices.Data.Application two years ago.
A year ago, I chose linq to sql.
Now I choose nhibernate.
On NHibernate Mappin
(1) if you are a beginner, match it by yourself.
(2) if you like linq, there is a FluentNHibernate to choose from (please consider the risk with the new technology, it's okay to play)
(3) if you are familiar with mapping configuration files, use NHibernate.Mapping.Attributes tags to generate them automatically (code generators are not recommended, they all need to be changed)
5. Compare java web classic platforms
Fortunately, the web programming architecture that has come into contact with java,java before is very stable, 3 years ago, it is still the same now, the only difference is the version upgrade, which .net programmers are miserable. This also testifies to the fact that spring,hibernate,struts (webwork) is currently a partner of the government.
Change to. Net platform, that is, spring.net (Ioc container) + nhibernate (orm) + asp.net mvc.
Both spring.net and nhibernate belong to java transplant products, so it should be said that there are a lot of materials. People who want to learn should focus on the java community and gain a lot. It would be nice to compare c # and java language slightly (don't go to learn java:).
Asp.net mvc is much more convenient than struts, but the difference is that there are more products attached to java. For frameworks like asp.net mvc, some frameworks of java have begun to improve (see, the idea is basically the same).
Of course, the open source route adopted here, we can also use the technology of Microsoft's own platform.
two。 Technical series
1. Register the container
two。 Initialize Nhibernate
We all know that Ioc can combine with asp.net mvc.
3.Nhibernate and container matching method
(1) there are already classic examples of the combination of Nhibernate and spring.net. What is a classic example is that everyone does it, and there is nothing wrong with it. I just do it. It makes some sense. Although sometimes I don't know why I do it. He he
(2) register at the start of the application in a single case, as described above
(3) if Nhibernate is mapped into FluentNHibernate, or if linq to nh is added, the whole design will be reconsidered.
I think the above design is a little interesting, especially with the addition of linq to nh. My idea is this.
(1) simple query with linq to nh
(2) hql main hit, standard query assistance.
(3) if you are not familiar with the nh framework, you can't find it, or if you encounter a slow speed, go to t-sql first (the reason is usually caused by poor self-study, doubt yourself first, doubt yourself no longer, and then doubt the framework itself.)
three。 Project subdivision
Ignoring distributed applications here, I haven't specifically done it.
Entity project one
A Service interface project
The Service interface implements a project by default
Domain project one
A project of the main auxiliary class (for miscellaneous purposes)
Test one project (optional)
A project related to web (put web related and controller)
Web hit a main project (run the project, mainly put js to use.)
Basically, you can subdivide or merge many of the above projects into the same project.
Multi-use reflection and configuration files if you want to be flexible
four。 Refinement
If you want to complete the general data addition, deletion and modification system, we can also slightly refine the encapsulation, which is very convenient.
1. There is no absolute flexibility, and some coupling is needed. The ext framework has certain requirements for the json data requested by the back end, so data conversion is inevitable, so prepare some general data type conversion functions.
two。 For the same data addition, deletion and modification, if there is no special business logic, it can be done with the help of asp.net mvc and reflection functions, so the design of a controller can replace many.
3. Do not use features such as delayed loading when transmitting json.
4. A hql configuration system, do not rewrite the code because a query condition has changed, you can consider making a mechanism to extract the hql statement.
5. Log is essential for skillful use of nhibernate interception mechanism
6. A set of stable authority mechanism
7. For ext, it is necessary to have a js loading mechanism
Thank you for reading this article carefully. I hope the article "how to build a Web Framework based on .NET platform" shared by the editor will be helpful to you. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.