是否有对的Application_Start在C#中的类库等效 [英] Is there an equivalent of Application_Start for a class library in c#

查看:212
本文介绍了是否有对的Application_Start在C#中的类库等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在类库执行某些code,当它从另一个组件实例化。是否有一个入口点或引导的一个类库?我认为,一个静态方法主要会做的伎俩,但我错了。 申请这​​可能是配置和实例化一个记录单,未处理的异常处理程序等。

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.

推荐答案

你有没有调查过的 preApplicationStartMethodAttribute

using System.Web;

[assembly: PreApplicationStartMethod(typeof(ClassLibrary.Startup), "Start")]

namespace ClassLibrary
{
    public class Startup
    {
        public static void Start()
        {
            // do some awesome stuff here!
        }
    }
}

更多细节:的http://dochoffiday.com/professional/simulate-application-start-in-class-library

这篇关于是否有对的Application_Start在C#中的类库等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆