I know this question is similar to several previous ones, but I can't find an exact answer. I have an application framework that, amongst other things, handles unhandled errors. At the moment I require that the host application calls a Register
method in the application's Main
method to register the handlers and various sub-systems. I'd really like to get rid of this dependency and replace the Register
method's parameters with some assembly-level attributes. So, what I need is a way of detecting that the host application has started from within my assembly - as if it were part of the .NET framework.
I'd like to avoid any explicit calls from within the host app, or any special lines in the configuration file (although these are more acceptable). So just adding a reference to the assembly causes the features to be initialised when the application starts. Has anyone worked out a way of making this happen?
To make things clear, here is an example of my ideal before and after scenarios:
// BEFORE:
[System.STAThread]
private static int Main(string[] args)
{
SupportLibrary.Register(typeof(Program).Assembly, SupportLibrary.ApplicationType.WinForms);
// Get the application initialised...
}
// AFTER:
[System.STAThread]
[SupportLibrary.ApplicationType(SupportLibrary.ApplicationType.WinForms)]
private static int Main(string[] args)
{
// Get the application initialised...
}
The point being that I would like to get rid of the explicit call to register the support libraries and instead have them implicit registered when the application starts and the support assembly loads.