구조 맵 및 스캐닝 어셈블리
-
21-08-2019 - |
문제
따라서 StructureMap을 사용하는 .NET 솔루션이 있으며, 해당 솔루션의 프로젝트의 인터페이스를 구현하고 레지스트리 항목을 정의하는 외부 어셈블리를 읽고 싶습니다.
내 솔루션의 structremap 구성 :
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();
});
});
매우 간단하게, 나는 디렉토리에서 어셈블리 컬렉션에 호출 어셈블리와 어셈블리를 추가하라고 말합니다. 어셈블리 변수를 디버깅했으며 실제로 모든 어셈블리를 찾았습니다 (Extensions Directory의 어셈블리 포함).
DLL 프로젝트에서 원래 솔루션과 분리 된 DLL 프로젝트에서 인터페이스를 구현하고 (원래 솔루션에서 인터페이스 프로젝트를 참조했습니다) 매우 간단한 레지스트리를 작성했습니다.
public class ProductMockRegistry : Registry
{
public ProductMockRegistry()
{
ForRequestedType<IProductRepository>().AddInstances(repository =>
{
repository.OfConcreteType<ProductMockRepository>();
});
}
}
내가 가지고있는 문제는, structuremap은 외부 DLL에서 레지스트리를 찾지 않는다는 것입니다. 그것은 DLL을 잘 발견하지만, 내가 lookforregistries라고 말하면 그것을 찾지 못합니다.
제휴하지 않습니다 StackOverflow