Is there an equivalent of Application_Start for a class library in c#

Diego picture Diego · Oct 5, 2011 · Viewed 12.4k times · Source

I would like to execute certain code in a class library when it is instantiated from another assembly. Is there an entry point or bootstrap for a class library? I thought that a static method Main would do the trick but I was wrong.

Applications for this might be configuring and instantiating a logger singleton, unhandled exception handler, etc.

Answer

Ixer picture Ixer · Jan 2, 2020

A library as it is, has not an starting point. When you are instancing a class of a library the first instruction you call is the constructor of the class (new) and its base constructors if they are on the constructor definition.