Is there a standard mechanism by which it would be possible to automatically execute certain code when the assembly is loaded into the domain? It is clear that it is easy to implement this (mark assemblies with your own attribute indicating the type in which the static constructor should be placed initialization code, subscribe to AppDomain.CurrentDomain.AssemblyLoaded and pull the specified type in the handler if the assembly is marked), mechanism, if any.

    1 answer 1

    Personally, it seems to me that the AssemblyLoaded event is just the "standard mechanism" for such purposes.

    And how to use it - that is, everything that you have written in the question, including the use of custom attributes and tagging assemblies - is just some syntactic sugar that is somehow distributed by AssemblyLoaded .


    Another thing is that, in general, the task of executing the necessary code at the moment of loading some assembly is nontrivial and is correctly solved only with the help of module initializers.

    I recommend reading .Net: Running code when assembly is loaded , if there are more questions, I am ready to answer.