how to write class lib's assembly load/init event handler

佐手、 提交于 2019-12-22 08:29:27

问题


I am trying to convert Java libs to c# libs. I am stuck at a place and could not find any solution via googling. The issue is in c# Class Lib i want to write assembly load/init event handler, is it possible as in Java it seems is? In java the code is.

public class abc implements ServletContextListener {

public void contextInitialized(ServletContextEvent event) {
    //do something
}

public void contextDestroyed(ServletContextEvent event) {
    //do something
}
}

what would be its equivalent in c#?


回答1:


There is an AssemblyLoad event in the AppDomain class that may be what you are looking for:

    private void SomeMethod() {
        AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
    }
    void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) {
        // Code to initialize here...
    }


来源:https://stackoverflow.com/questions/4020178/how-to-write-class-libs-assembly-load-init-event-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!