【问题标题】:Autofac equivalent of StructureMap's WhatDoIHave()Autofac 等效于 StructureMap 的 WhatDoIHave()
【发布时间】:2016-09-22 16:04:05
【问题描述】:

Autofac 有类似StructureMap's WhatDoIHave() 的方法吗?我希望能够直观地看到当前在我的容器中注册了哪些服务。我查看了 Autofac 的文档,找不到类似的东西。

如果不存在这样的方法,Autofac 是否存在技术问题使其难以实施,或者只是没有兴趣提供类似的方法?

【问题讨论】:

  • 没有技术问题。 Glimpse 有一个 Autofac 模块,它以与WhatDoIHave() 结果类似的格式列出注册。我不知道有任何内置的可视化辅助工具。

标签: c# autofac


【解决方案1】:

您可以使用IComponentRegistryRegistrationFor 方法来获取所有已注册的服务。您可以使用IComponentContextComponentRegistry 方法访问组件注册表(即:ILifetimeScopeIContainer

IContainer container = builder.Build(); 

container.ComponentRegistry.RegistrationFor(new TypedService(typeof(IXService));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多