Preapplicationstartmethod Feature Description

Source: Internet
Author: User

Preapplicationstartmethod used primarily to specify a method for an assembly , Some custom initialization processing occurs when the assembly is loaded.

Use the following as shown, first defining a public type and a public static method in the assembly

then we use Preapplicationstartmethod property to register the method for the preprocessing of the Assembly, note Preapplicationstartmethod only methods in the type in the current assembly can be registered for preprocessing, and the type must be Public , the change method must be Public Static .

We then follow the steps above to create a new number of identical projects

Finally, we create a new empty MVC projects, referencing these class library projects, testing the assemblies

Run the program and you can see Class1 , Class2 , CLASS3 in the Run method executes sequentially

Global the events in the file, such as Application_Start , will be executed after they're done.

as shown above, the current Web Project references three class library projects, what are the rules for the execution order of their respective preprocessor codes?

View MSDN on Preapplicationstartmethodattribute description of the type, you can see that we cannot control the order in which the code is processed, that the preprocessor code is compiled, that the code is independent, and that the order in which the preprocessing code is executed does not affect the operation of the program.

also, if the current Web The project also has preprocessing code, then the preprocessor code of the externally referenced assembly is associated with the Web The preprocessing code in the project, which will take precedence?

the new Class4 is shown below and is registered with the Run method for preprocessing

as you run the site, you can see thatthe run method in Class4 executes after the preprocessor in the externally referenced assembly has finished executing, the relevant event code in the Global file will not be executed until the C13>class4.run execution is complete .

because the preprocessed code executes when the program is first run and the assembly is loaded. So in the MVC5 and Katana projects, we use the preapplicationstartmethod feature to HttpModule Dynamic registration of the.

Preapplicationstartmethod Feature Description

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.