Answer the question
In order to leave comments, you need to log in
Creating an Instance class in Global.asax. Not dangerous?
There is a class library FilterPlugin.
All classes implement a certain interface.
In Global.asax, I decided to collect all Instance of these classes into a global variable for further use.
Here is the function to write Instance in global.asax:
private void FilterPluginConfig()
{
string[] addInAssemblies = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/bin"), "FilterPlugin.dll");
foreach (var file in addInAssemblies)
{
Assembly addInAssembly = Assembly.LoadFrom(file);
foreach (var t in addInAssembly.GetExportedTypes())
{
if (t.IsClass && typeof(IFilterPlugin).IsAssignableFrom(t))
{
GeneralSettings.FilterPluginsInstances.Add((IFilterPlugin)Activator.CreateInstance(t));
}
}
}
}
foreach (var filter in GeneralSettings.FilterPluginsInstances)
{
filter.GiveResult();
}
Answer the question
In order to leave comments, you need to log in
State your doubts. I personally don't see any crime, unless the download fails or someone replaces FilterPlugin.dll
The only thing, when unit testing, there may be problems when initializing your filter array. Yes, and many singletons (and the static class is actually a singleton) are considered an antipattern for this reason, the code becomes more tied, and in principle a normal solution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question