I need someone to explain to me what exactly the AssembliesInBaseDirectory method returns. I have inherited an application that has the following code:
namespace Infrastructure.Common {
public static class GlobalContainer
{
private static IUnityContainer _unityContainer;
public static IUnityContainer CreateUnityContainer()
{
var unityContainer = new UnityContainer();
unityContainer.Configure(unityRegistry => unityRegistry.AddRegistry<CommonRegistry>());
return unityContainer;
}
public static IUnityContainer Unity
{
get { return _unityContainer ?? (_unityContainer = CreateUnityContainer()); }
set { _unityContainer = value; } // For testability
}
}
}
This GlobalContainer registers another registry called CommonRegistry and this is the code for that:
namespace Infrastructure.Common
{
public class CommonRegistry : IocRegistry
{
public CommonRegistry()
{
const StringComparison strCmp = StringComparison.InvariantCultureIgnoreCase;
Scan(scan =>v{
scan.AssembliesInBaseDirectory(a => a.GetName().Name.StartsWith(@"Pharmacy.", strCmp)
|| a.GetName().Name.StartsWith(@"PharmacyServer.", strCmp)
|| a.GetName().Name.StartsWith(@"CDM.", strCmp)
|| a.GetName().Name.StartsWith(@"Commerce.", strCmp)
|| a.GetName().Name.StartsWith(@"Infrastructure.", strCmp)
|| a.GetName().Name.StartsWith(@"Audit.", strCmp)
|| a.GetName().Name.StartsWith(@"Authentication.", strCmp)
|| a.GetName().Name.StartsWith(@"LaSuite", strCmp));
scan.ForRegistries();
});
}
protected override void Register()
{
RegisterWithConstructor<IUserContextProvider, UserContextProvider>(new IocInjectionConstructor());
RegisterWithConstructor<ITenantProvider, TenantProvider>(new IocInjectionConstructor(new IocResolver<IUserContextProvider>()));
Register<IImageProcessor, ImageProcessor>();
Register<IValidationHelper, ValidationHelper>();
Register<IClaimingHelper, ClaimingHelper>();
Register<ICertificateHelper, CertificateHelper>();
}
}
}
I'm trying to understand the call to scan.AssembliesInBaseDirectory. You see, my solution has many many projects that use GlobalContainer. Some are WCF services, some are console applications. I want to know, when this method is called from the WCF service, what assemblies are being scanned? Where is it looking? When it is used in the console application, where is it looking? It seems to me that the base directory changes depending on who is using GlobalContainer. Is it looking for the assemblies that start with the given strings inside each of these projects (WCF and console)? I'm new to Ioc.