using System; using System.Collections.Generic; using System.Reflection; using System.Text; namespace Mini.Common { /// /// Provides information about types in the current web application. /// Optionally this class can look at all assemblies in the bin folder. /// public class WebAppTypeFinder : AppDomainTypeFinder { #region Fields private bool _ensureBinFolderAssembliesLoaded = true; private bool _binFolderAssembliesLoaded; #endregion #region Properties /// /// Gets or sets whether assemblies in the bin folder of the web application should be specifically checked for being loaded on application load. This is need in situations where plugins need to be loaded in the AppDomain after the application been reloaded. /// public bool EnsureBinFolderAssembliesLoaded { get { return _ensureBinFolderAssembliesLoaded; } set { _ensureBinFolderAssembliesLoaded = value; } } #endregion #region Methods /// /// Gets a physical disk path of \Bin directory /// /// The physical path. E.g. "c:\inetpub\wwwroot\bin" public virtual string GetBinDirectory() { //if (HostingEnvironment.IsHosted) //{ // //hosted // return HttpRuntime.BinDirectory; //} //else //{ //not hosted. For example, run either in unit tests return AppDomain.CurrentDomain.BaseDirectory; //} } public override IList GetAssemblies() { if (this.EnsureBinFolderAssembliesLoaded && !_binFolderAssembliesLoaded) { _binFolderAssembliesLoaded = true; string binPath = GetBinDirectory(); //binPath = _webHelper.MapPath("~/bin"); LoadMatchingAssemblies(binPath); } return base.GetAssemblies(); } #endregion } }