C # project architecture construction experience

Source: Internet
Author: User

C # project architecture construction experience
Read. in the. Net project, I felt that the code was well written (Note 1): bbsMax (unfortunately, it seems like the birds have disappeared), Umbraco (a foreign open-source cms project ), kooboo (Open Source cms in China ). I am narrow-minded. I do not read much code and have a wide range. Have you always been eager to develop a system architecture that makes people read and feel that the program is organized and the structure is reasonable. Good architects must have: 1. Rich project experience. (It should have come out of a pile of projects, with a wealth of experience more profound than the theory of big theory .) 2. Comprehensive knowledge and solid foundation. (You do not need to know anything about the comprehensiveness of knowledge. At least you must be familiar with WCF, Silerlight, WebService, WindowService, Asp.net, WinForm, Asp.net Mvc, ORM (Entity Framework, Linq, nhib.pdf) DI/IOC (Autofac, Unity, Cast), Javascript (javascript can encapsulate class libraries by itself, very skilled in jquery), Ajax (js help method, AjaxPanel), OAuth (Open Identity ), OData, etc.) 3. you will understand the problem from different perspectives. (But you don't have to understand every language. At least you can't understand only one technology. When you read the architecture implemented by different languages, it will bring you a different feeling and a way to handle things. For example, Django or Ruby On Rails can help you understand the true meaning of the MVC Architecture. The feeling of reading struts in Java is different.) 4. Skilled application of the design pattern. (Behavior model, structure mode, Creation Mode) 5. Strong interest in programs. (If you only use the program as a skill in exchange for income, it is difficult to become a senior level. in your spare time, [What are you busy at, what will you gain in your future.] (Note 2) Can you do this on a daily basis? From graduation to leaving this industry, the business time has always regarded the program as your hobby, whether it can be something that can enrich you in your spare time) 6. is Science Excellent. (Whether you believe it or not, if your science is poor, it will take a long time for you to become a master of computer technology.) How to Build a c # project architecture that runs like a computer? 1. boot. cs, where it should appear in the project, and what it can do. Configuration information management class initialization (loading )... System Information Management class initialization (loading )... Business subscription implementation initialization (loading )... Initialize (load) The system adaptation management class )... Template engine initialization (loading )... Theme Management class initialization (loading )... Plugin management class initialization (loading )... Widget management class initialization (loading )... Data operation implementation class initialization (loading )... Implementation example: 1 protected void Application_BeginRequest (object sender, EventArgs e) 2 {3 if (false = hasInit) 4 {5 lock (locker) 6 {7 if (false = hasInit) 8 {9 // when the first HttpApplicaiton initial instantiation, start the Global static variable information in the Boot class 10 // AllEnums initialization: contains the Enum attribute, field, annotation information, to avoid dynamic creation every time the enum context information is used; 11 // AllSettings initialization: to avoid multiple global unique configuration management class initialization, ensure that an object instance is retained in the application pool 12 // initialization (loading) of the configuration information management class )... 13 // initialize (load) The system information management class )... 14 // business subscription implementation initialization (loading )... 15 // initialize (load) The system adaptation management class )... 16 // template engine initialization (loading )... 17 // theme management class initialization (loading )... 18 // plugin management class initialization (loading )... 19 // widget management class initialization (loading )... 20 // data operation implementation class initialization (loading ).. 21 Boot. init (); 22} 23} 24} 25 26 // at the beginning of each http request, you must initialize the http context packaging class 27 AppContext. init (); 28 ...... 29} 30 31 // <summary> 32 // start time 33 // </summary> 34 public class Boot35 {36 /// <summary> 37 /// initialization... 38 /// </summary> 39 public static void Init () 40 {41 // global system variable loading 42 Globals. init (); 43 44 // globally unique configuration information loaded 45 SettingsManager. init (); 46 47 // global Enums context load 48 AllEnums. init (); 49 // global configuration information AllSettings. init (); 50 // initialize Theme proxy implementation class 51 ThemeProxies. proxies. clear (); 52 ThemeProxies. proxies. add (new DefaultThemeProxy (); 53 ...... 54} 55} skin management example: 1 public interface IThemeProxy 2 {3 List <Theme> Load (); 4 5 List <TemplateInfo> Load (string dir ); 6 7 string Load (string file); 8 9 Theme GetDefault (); 10 11 void SetDefault (Theme theme); 12 13 void Delete (Theme theme ); 14 15 void Upload (Theme theme); 16 17 void Save (string file, string fileContext); 18} 1 public class ThemeProxyCollection: collection <IThemeProxy> 2 {3 4} copy code 1 public Class ThemeProxies2 {3 public static ThemeProxyCollection Proxies = new ThemeProxyCollection () {4 new DefaultThemeProxy () 5}; 6} 2. AppContext. cs, what role it plays and what it can do. Skin management, handling of errors and tracking information, storing and obtaining context temporary variables, currently accessed users (basic account information, permission information), and so on 3. global. cs (AppRuntime. cs). When you see this class, you can think of what it can do and what role it plays in the system architecture. System parameter information... Config configuration information... System Path to quickly obtain help functions... 4. system configuration, the Enum type that often appears in the system, how to make your system feel clean and tidy. AllEnums. cs to maintain the context of global enum... AllSettings. cs to maintain global configuration information... Wait 1 /// <summary> 2 // global enum object member information management class 3 /// </summary> 4 public class AllEnums 5 {6 public AllEnums () 7 {8} 9 10 public static EnumInfoCollection CategoriesTypeMembers {get; set ;} 11 12 /// <summary> 13 // initialize the global enum object member information 14 /// </summary> 15 public static void Init () 16 {17 CategoriesTypeMembers = EnumUtil. getEnumItems (typeof (CategoriesType); 18 19} 20} 1 public class EnumInfo: IPrimaryKey <String> 2 {3 // Methods 4 public string GetKey () 5 {6 return this. name; 7} 8 9 // Properties10 public string DefaultValue {get; set;} 11 12 public string Description {get; set;} 13 14 public string Name {get; set ;} 15 16 public object Value {get; set;} 17} 18 19 public class EnumInfoCollection: Collection <EnumInfo> 20 {21 // Methods22 public EnumInfoCollection () 23 {24} 25 26 public EnumInfo Collection (EnumInfoCollection items) 27 {28 if (items! = Null) 29 {30 foreach (EnumInfo info in items) 31 {32 base. add (info); 33} 34} 35} 36} 1 public enum CategoriesType: int 2 {3 [Description ("")] 4 [DefaultValue (0)] 5 Article, 6 7 [Description ("")] 8 [DefaultValue (1)] 9 Product, 10 11 [Description ("")] 12 [DefaultValue (0)] 13 Dowload, 14 15 [Description ("")] 16 [DefaultValue (0)] 17 Images, 18 19} 1 public class EnumUtil 2 {3 public static EnumInfoCollection GetEnumItems (Type enumType) 4 {5 EnumInfoCollection infos = new EnumInfoCollection (); 6 FieldInfo [] fields = enumType. getFields (BindingFlags. public | BindingFlags. static | BindingFlags. declaredOnly); 7 foreach (FieldInfo info2 in fields) 8 {9 EnumInfo item = new EnumInfo10 {11 Name = info2.Name12}; 13 DescriptionAttribute [] customAttributes = (DescriptionAttribute []) info2.Get CustomAttributes (typeof (DescriptionAttribute), true); 14 if (customAttributes! = Null) & (customAttributes. length> 0) 15 {16 item. description = customAttributes [0]. description; 17} 18 DefaultValueAttribute [] attributeArray2 = (DefaultValueAttribute []) info2.GetCustomAttributes (typeof (DefaultValueAttribute), true); 19 if (attributeArray2! = Null) & (attributeArray2.Length> 0) 20 {21 item. defaultValue = attributeArray2 [0]. value as string; 22} 23 object obj2 = enumType. invokeMember (info2.Name, BindingFlags. getField, null); 24 switch (Enum. getUnderlyingType (enumType ). fullName) 25 {26 case "System. int32 ": 27 item. value = (int) obj2; 28 break; 29 30 case "System. int16 ": 31 item. value = (short) obj2; 32 break; 33 34 case "System. byte ": 35 item. value = (byte) obj2; 36 break; 37 38 case "System. UInt16 ": 39 item. value = Convert. toInt32 (ushort) obj2); 40 break; 41 42 case "System. UInt32 ": 43 item. value = (int) obj2; 44 break; 45 46 case "System. UInt64 ": 47 item. value = (int) obj2; 48 break; 49} 50 infos. add (item); 51} 52 return infos; 53} 54 55 public static bool TryParse <T> (string memberName, out T t) where T: struct56 {57 t = default (T); 58 retur N (! MemberName. isNullOrEmpty () & Enum. tryParse <T> (memberName, true, out t); 59} 60 61} 5. data operation class, how to deal with it makes the DataAccess layer more standard. 6. How to manage Plugin. 7. How to manage Widgets. 8. are you still sticking to layers like Dao, Business, Web, and Entity (Model. net (cms), PetShop spread out of the structure, whether or not your on the program structure of creative ideas. 9. Template Engin. Have you tried to handle the implementation? Please discard the NVelocity poison. Is it possible from Discuzz! NT get some inspiration. Or are you clear about the operating principle of the Asp.net mvc template and whether the implementation principle can be found in the core code implementation. 10. pseudo-static, principle, and implementation. Whether or not it has been used. 11. Do you attempt to use the static HTML generation system or write it yourself. 12. interface Class, abstract class, implementation class, management class, proxy class, creation class, behavior class, decoration class, real type class, enumeration class, etc, do you think carefully about the names, storage locations, and structure of classes when creating programs.

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.