Re: выполнить метод после загрзки сборки
От: QrystaL Украина  
Дата: 22.04.14 18:02
Оценка: 136 (4) +1
Здравствуйте, -rsdn-, Вы писали:

R>допустим у меня есть веб приложение, оно использует dllку. перед тем как вызвать любой метод из dll я хочу что бы в dll вызвался метод например OnLoading

R>как такое сделать?

PreApplicationStartMethodAttribute
This new attribute allows you to have code run way early in the ASP.NET pipeline as an application starts up. I mean way early, even before Application_Start. This happens to also be before code in your App_code folder (assuming you have any code in there) has been compiled. To use this attribute, create a class library and add this attribute as an assembly level attribute. A common place to add this would be in the AssemblyInfo.cs class within the Properties folder. Here’s an example:

[assembly: PreApplicationStartMethod(typeof(SomeClassLib.Initializer), "Initialize")]


Note that I specified a type and a method. That method needs to be a public static void method with no arguments. Now, any ASP.NET website that references this assembly will call the Initialize method when the application is about to start, giving this method a chance to do perform some early initialization.

public static class Initializer
{
  public static void Initialize() { 
    // Whatever can we do here?
  }
}


http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.