小编use*_*155的帖子

Simple Injector,无法覆盖现有注册

我目前第一次使用Simple Injector.在我的.NET项目中,我正在运行测试和模拟从Web服务返回的数据并将对象注册到容器中

 _container.Register<IWebServiceOrder>(() => mock.Object, Lifestyle.Transient);
Run Code Online (Sandbox Code Playgroud)

这很好用.但在我的测试中,我想在第二次调用包含更新数据的Web服务时测试系统的行为,因此需要更新模拟对象.

默认情况下,Simple Injector不允许覆盖现有注册,但官方网站声明可以更改此行为,如下所示.

https://simpleinjector.readthedocs.org/en/latest/howto.html#override-existing-registrations

container.Options.AllowOverridingRegistrations = true;
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我尝试第二次注册对象时,即使使用上面的代码,我仍然会收到错误.

首次调用GetInstance,GetAllInstances和Verify后,无法更改容器

有关为什么会发生这种情况的任何想法?

c# simple-injector

6
推荐指数
1
解决办法
2631
查看次数

标签 统计

c# ×1

simple-injector ×1