从评论中,我可以看到我会编写自己的集成测试,但希望将来能够在NdDepper中得到支持。
如何创建自定义NDEPER规则以检查DI注册
题
我们将AUTOFAC用作依赖注入的容器。我们想使用Ndependection检查各种事情,以确保我们的DI设置正确并不被滥用(我们有一个很大的解决方案)。
在单元测试中,我可能会采取一种方法:
private static IEnumerable<TestCaseData> TestCases
{
get
{
return from registration in Container.Value
.ComponentRegistry.Registrations
from service in registration.Services
where service is TypedService
orderby service.Description
select new TestCaseData(registration, service)
.SetName(service.Description);
}
}
然后:
[Test]
[TestCaseSource("TestCases")]
public void CanBeResolved(
IComponentRegistration componentRegistration,
TypedService typedService)
{
using (var scope = Container.Value.BeginLifetimeScope())
scope.Resolve(typedService.ServiceType);
}
我如何在NDEDECT中创建自定义规则,以确保所有适当的类型均在AutoFac容器中注册?
谢谢理查德
解决方案
不隶属于 StackOverflow