Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 453
Diego Avatar asked Oct 04 '11 23:10

Diego


People also ask

Can class library have app config?

No, class libraries can hold setting files, but their values will be defined in the application configuration (web. config, app.

What is a class library project in c#?

A class library defines types and methods that are called by an application. If the library targets . NET Standard 2.0, it can be called by any . NET implementation (including . NET Framework) that supports .

When to use class library c#?

Using libraries is useful when you want to share code between multiple programs. If you think you will need your classes to sanitize data in more than one program, this is a good idea to put them in a library.


1 Answers

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.

like image 125
Ixer Avatar answered Oct 15 '22 19:10

Ixer