StructureMap和扫描程序集 [英] StructureMap and scanning assemblies
问题描述
因此,我有一个使用StructureMap的.NET解决方案,我想让StructureMap读取一个外部程序集,该程序集实现该解决方案中项目的接口并为其定义注册表项.
So, I have a .NET solution that uses StructureMap, and I'd like to have StructureMap read an outside assembly that implements an interface from a project in that solution and defines the registry entry for it.
我的解决方案的StructreMap配置:
StructreMap configuration for my solution:
ObjectFactory.Initialize(registry =>
{
registry.Scan(assembly =>
{
assembly.TheCallingAssembly();
//Telling StructureMap to sweep a folder called "extensions" directly
//underneath the application root folder for any assemblies found in that folder
assembly.AssembliesFromPath("extensions", addedAssembly => addedAssembly.GetName().Name.ToLower().Contains("extension"));
//Direct StructureMap to add any Registries that it finds in these assemblies, assuming that all the StructureMap directives are
//contained in registry classes
assembly.LookForRegistries();
});
});
非常简单,我告诉它将调用程序集和该程序集从目录添加到Assemblys集合中.我已经调试了assemblys变量,它确实找到了所有程序集(包括来自extensions目录的程序集).
Pretty straightforward, I tell it to add the calling assembly and the assembly from a directory to the assemblies collection. I've debugged the assemblies variable and it has indeed found all the assemblies (including the one from the extensions directory).
在我与原始解决方案分开创建的DLL项目中,我实现了一个接口的实现(我从原始解决方案中引用了接口项目),并编写了一个非常简单的注册表:
In a DLL project I've created separate from my original solution, I have an implementation of an interface (I've referenced the interfaces project from my original solution), and written a very simple registry:
public class ProductMockRegistry : Registry
{
public ProductMockRegistry()
{
ForRequestedType<IProductRepository>().AddInstances(repository =>
{
repository.OfConcreteType<ProductMockRepository>();
});
}
}
我的问题是,StructureMap在外部DLL中找不到注册表.它发现DLL很好,但是当我告诉LookForRegistries时,找不到它.
The problem I have is, StructureMap does not find the registry in the external DLL. It finds the DLL just fine, but when I tell it to LookForRegistries, it doesn't find it.
推荐答案
这篇关于StructureMap和扫描程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!