我该怎么做的依赖注射在一个试验项目(TFS2008年)使用的城堡
-
01-07-2019 - |
题
我使用的是温莎城堡依赖注射在我的试验项目。我试图创建的一个实例,我的一个'库'类。"它的工作现在我的机器",但当我运行了一夜间建立在TFS,我的测试都是不够载所述课程。
private static readonly WindsorContainer _container = new WindsorContainer(new XmlInterpreter());
public void MyTestInitialize()
{
var testRepository = (IBogusRepository)_container[typeof(IBogusRepository)];
}
xml的配置:
<castle>
<components>
<component id="primaryBogusRepository" type="Example2008.Repository.LALALALALA, Example2008.Repository" service="Example2008.Domain.Repository.IBogusRepository, Example2008.Domain" />
<component id="primaryProductRepository" type="Example2008.Repository.ProductRepository, Example2008.Repository" service="Example2008.Domain.Repository.IProductRepository, Example2008.Domain" />
</components>
</castle>
当我排队新建立它生产 以下信息:
无法创建的实例类 Example2008.测试。ActiveProductRepositoryTest.错误:系统。配置。ConfigurationException:这种类型的名字 Example2008.库。LALALALALA, Example2008.存储库不可能 位置。
城堡。温莎。安装。DefaultComponentInstaller.ObtainType(String typeName) 城堡。温莎。安装。DefaultComponentInstaller.SetUpComponents(合[] 配置,IWindsorContainer 容器) 城堡。温莎。安装。DefaultComponentInstaller.设置(IWindsorContainer 容器,IConfigurationStore商店) 城堡。温莎。WindsorContainer.RunInstaller() 城堡。温莎。WindsorContainer..构造函数(IConfigurationInterpreter 翻译) Example2008.测试。ActiveProductRepositoryTest..cctor() 在d:\Code_Temp\Example 项目 每晚\源\Example2008.试验\ProductRepositoryTest.cs:19行
从这一消息,看来我的配置是正确的(它可以看到,我想到的实例的具体类'LALALALALA',所以xml配置显然是红色的正确)
我认为我有我的依赖关系的设置是否正确,以及(因为它的工作原理在本地,甚至如果我干净的解决方案和重建).
任何想法?
(使用VS2008,TFS2008.Net 3.5,城堡1.03,通过这种方式)
解决方案
那是...很有趣。我找到了 这篇博客,可以帮助你的问题。 它看起来像MSTest是使用,作为其工作的目录,这是令人讨厌的,至少可以说。博客后显示如何改变目录,这样就可以有一致的结果。我也会做一些Google搜索发现,如果更加优雅的解决方案的存在。
其他提示
这听起来像会持有的储存库的实现缺失,bin directory(或任何执行目录是为建立).
我将首先检查,看看会否存在构建服务器的执行目录。
如果它确实存在,那么我会检查,以确保该版本的会是正确的,即已经储存库的执行关于在相同的名字空间等。
这可能是因为你的建立服务器是执行/建设的对象在其他地方比这里VS是执行/建设。