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