asp.net mvc的测试项目无法找到文件温莎

编程入门 行业动态 更新时间:2024-10-11 11:18:46
本文介绍了asp mvc的测试项目无法找到文件温莎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好im使用温莎作为一个DI容器,

Hi there Im using windsor as a DI container,

我的code低于

public static class ContainerBuilder { public static IWindsorContainer Build() { var container = new WindsorContainer("Configuration\\Windsor.config"); // automatically register controllers container.Register(AllTypes .Of<Controller>() .FromAssembly(Assembly.GetExecutingAssembly()) .Configure(c => c.LifeStyle.Transient.Named(c.Implementation.Name.ToLower()))); container.Register( Component.For<IServiceLocator>().Instance(new WindsorServiceLocator(container)), Component.For(typeof(IRepository<>)).ImplementedBy(typeof(NHibernateRepository<>)).LifeStyle.Transient ); return container; } }

我需要从一个测试项目的话,这个问题是,当我这样做的windsor.config从未发现和试验似乎总是失败,这里是把这个配置文件的最好方法还是有更好的方法来这样做呢?谢谢

I need to call this from a test project , the problem is that when I do this the windsor.config is never found and the test seems to always fail, where is the best way to place this config file or is there a better approach to doing this? Thanks

推荐答案

只要在配置路径配置,例如

Just make the config path configurable, e.g.

public static IWindsorContainer Build(string configPath) { var container = new WindsorContainer(configPath); ... }

在您的应用程序的configPath来配置\\ Windsor.config,而在你的测试,你就会有一个像路径.... \\配置\\ Windsor.config。

In your app the configPath is "Configuration\Windsor.config" while in your tests you'll have a path like "....\Configuration\Windsor.config".

请注意,你不应该通常取决于你的测试容器上,除非你正在运行的一些集成测试。

Note that you shouldn't generally depend on the container in your tests, unless you're running some integration tests.

另外一个静态的集装箱制造商似乎并不像一个好主意,看看温莎安装的模块化的方式来注册你的组件。

Also a static container builder doesn't seem like a good idea, take a look at Windsor Installers to register your components in a modular way.

更多推荐

asp.net mvc的测试项目无法找到文件温莎

本文发布于:2023-11-16 01:56:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1599954.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:温莎   文件   测试   项目   asp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!