Open-source website. NETMVC + Layui + SqlSugar + RestSharp, layuisqlsugar
SugarSite is a front-end enterprise website that supports mobile terminals. Currently, only simple functions are supported, and forums will be added in the future.
Source code GIT address:
Https://github.com/sunkaixuan/SugarSite
Technical introduction Layui
Personally, I do not like to reference a bunch of things. The simpler the better, the layui can meet my needs. It is a lightweight UI, And the JS part uses a modular design (AMD ), relatively good support for mobile terminals.
The only disadvantage is that the number of components currently supported is relatively small, and talents with certain frontend scalability can be used with ease.
Usage:
For example, if I want to use form. js and uploda. js, I only need to write use (form, upload) (as shown in the following code) instead of referencing two JS files.
/* Demo1.js uses the form and upload components of Layui */layui. use (['terra', 'upload'], function () {// if only one component is loaded, you can leave the array empty. For example, layui. use ('form') var form = layui. form () // obtain the form component, upload = layui. uplaod; // obtain the upload Component // listener submit button });
SqlSugar
A high-performance, lightweight and powerful ORM framework that supports multiple databases and. net core. MySql supports read/write splitting and SQL supports parallel computing.
Asp.net 4. + |
Asp.net Core |
Description |
Dependency |
SqlSugar. dll |
SqlSugarCore. dll |
SqlServer ORM |
None |
MysqlSugar. dll |
MysqlSugarCore. dll |
MySql ORM |
MySql. Data. dll |
SqliteSugar. dll |
SqliteSugarCore. dll |
Sqlite ORM |
System. Data. SQLite. dll SQLite. Interop. dll (not required for Core Edition) |
OracleSugar. dll |
- |
Oracle ORM |
Oracle. ManagedDataAccess. dll |
SqlSugarRepository. dll |
- |
MySql Sqlite Oracle four-in-one |
MySql. Data. dll System. Data. SQLite. dll Oracle. ManagedDataAccess. dll SQLite. Interop. dll |
RestSharp
In my project, the function is similar to that of WCF. A core element of service-oriented programming is simpler and more lightweight than that of WCF, and only supports HTTP protocol.
Var client = new RestClient ("http: // localhost/home/getjson"); // client. authenticator = new HttpBasicAuthenticator (username, password); var request = new RestRequest ("resource/{id}", Method. POST); request. addParameter ("name", "value"); // Add the request parameter request. addUrlSegment ("id", "123"); // Add token // Add HTTP header request. addHeader ("header", "value"); // Add a file request. addFile (path); // execute the request IRestResponse response = client. execute (request); var content = response. content; // return the request object // or automatically deserialize result // return content type is sniffed but can be explicitly set via RestClient. addHandler (); RestResponse <Person> response2 = client. execute <Person> (request); var name = response2.Data. name; // supports client asynchronously. executeAsync (request, response => {Console. writeLine (response. content) ;}); var asyncHandle = client. executeAsync <Person> (request, response => {Console. writeLine (response. data. name) ;}); asyncHandle. abort ();
Design Concept adopted
Since ancient times, the design model has become more complex. The more people like to learn it, the more they can't understand what it is, even if they have learned it. They think this technology is brilliant, and the people who write it may not understand it themselves, on the contrary, the more people write code, the simpler they want to write.
There are no good or bad patterns:
Different people use different models to achieve different levels.
My insights
The nested logic cannot exceed three layers. If this constraint is not met, the write method in the United States must be concession.
1. redundant code is acceptable as long as it is well maintained. Copying and pasting Ling leads to code redundancy due to simple logic. If redundant code is required, the writing method is much more complicated, depending on the situation, you can choose not to have both fish and bear's paw.
2. Be sure to take the business as the core layer
3. When there is a conflict between easy-to-read code and less-modified writing, I will adopt easy-to-read writing (it doesn't matter if others don't understand the maintainability)
Code Description
Code structure:
I call this mode the Commander mode.
Glossary:
ViewAction:Action of the ActionResult type
ApiAction:Action of the JsonResult type, which is used as a business interface
Pack:A business block is isolated from each other. Each business block has multiple apiactions and multiple viewactions,
The communication between the business block and the Business block uses RestSharp to call the ApiAction of other packages.
Outsourcing:Some public code in the business block can be a class or a folder, depending on the complexity of the project
This architecture model has three advantages over the traditional three-tier architecture.
1. Easy layering and clearer code
In the past, data tables were used as services. If the SOA architecture was still abstracted, more than 10 tables would be processed for a complex business, the following figure shows the host Code. There are several tables with several services.
private x1 X1Service; private x2 X2Service; private X3 X3Service; public DocContentController(x1 X1Service, x3 X1Service, x4X1Service) { this.X1Service = X1Service; this.X2Service = X2Service; this.X3Service = X4Service; }
Now, you can get a processed service interface directly, instead of getting the table service in every detail.
_service.Command<HomeOutsourcing, ResultModel<DocResult>>((o, api) =>{ var DocLIST= api.Get(Url.Action("GetDoc"), new { typeId = typeId }); });
2. A set of codes can be used on multiple platforms.
Because it is based on ApiAction, if the permission is reasonable, it can be used as a mobile interface, but it is already an SOA architecture.
3. Simple hierarchy
Simpler than Layer 3
Complete function preview front-end
The front end perfectly supports all mainstream mobile terminals
Background
The background is simple and generous. It is not designed for the UI and is mainly practical. After IIS is released, it can detect a good sense of smoothness.
At present, only basic functions are completed, and this open-source project will be written in the future.
Recommended if you like
Source code GIT address:
Https://github.com/sunkaixuan/SugarSite