2009-02-03 78 views
7

所以,我有一個使用StructureMap的.NET解決方案,並且我想讓StructureMap讀取一個外部程序集,該程序集實現了該解決方案中項目的接口併爲其定義了註冊表項。我的解決方案StructureMap和掃描程序集

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(); 
    }); 
}); 

很簡單,我告訴它從目錄到組件集合添加調用組裝和裝配。我調試了程序集變量,它確實找到了所有程序集(包括來自擴展目錄的程序集)。

在我創建從我原來的解決方案分開的DLL項目,我有一個接口的實現(我引用從我原來的解決方案的界面項目),並寫了一個很簡單的註冊表:

public class ProductMockRegistry : Registry 
{ 
    public ProductMockRegistry() 
    { 
     ForRequestedType<IProductRepository>().AddInstances(repository => 
     { 
      repository.OfConcreteType<ProductMockRepository>(); 
     }); 
    } 
} 

我遇到的問題是,StructureMap沒有在外部DLL中找到註冊表。它發現DLL很好,但是當我將它告訴給LookForRegistries時,它找不到它。

回答