StructureMap 2.6.1.0 程序集扫描问题

发布于 2024-09-10 23:02:07 字数 427 浏览 0 评论 0原文

我试图使用 StructureMap 在运行时扫描包含注册表类实现的程序集,但我遇到了问题。

如果 dll 包含注册表类,但也包含对运行时不存在的 dll 的引用(例如运行时不需要的 Rhino.Mocks dll),则 StructureMap 将引发由 Assembly 产生的 StructureMapConfiguration 异常。 GetExportedTypes() 调用。

有没有办法避免 StructureMap 中的这种行为?

ObjectFactory.Initialize(x =>
{
    x.Scan(s =>
    {
        s.AssembliesFromApplicationBaseDirectory();
        s.LookForRegistries();
    });
});

I am trying to use StructureMap to scan at runtime for assemblies that contain an implementation of the Registry class, but I'm running into a problem.

If a dll contains a Registry class, but also contains a reference to a dll that isn't present at runtime (say a Rhino.Mocks dll that isn't required at runtime), StructureMap will throw a StructureMapConfiguration exception resulting from an Assembly.GetExportedTypes() call.

Is there a way to avoid this behaviour in StructureMap?

ObjectFactory.Initialize(x =>
{
    x.Scan(s =>
    {
        s.AssembliesFromApplicationBaseDirectory();
        s.LookForRegistries();
    });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

司马昭之心 2024-09-17 23:02:07

通过反射器,我发现通过调用 graph.Log.AssertFailures() 程序集扫描期间可能发生的任何异常(包括在 assembly.GetExportedTypes() 期间引发的异常,即您所指的异常)作为一个大例外抛出。我还没有发现任何表明可以以某种方式关闭此行为的信息。但我发现,如果您捕获异常,则扫描实际上会成功扫描它设法扫描的任何程序集。 StructureMap 实际上无法对调用 GetExportedTypes()(这是一个框架方法)时引发的异常执行任何操作,除非继续进行下一个程序集。如果您不介意“丢失”一些程序集,只需捕获异常并继续即可。

公共无效配置(操作配置)
{
锁定(这个)
{
ConfigurationExpression 表达式 = new ConfigurationExpression();
配置(表达式);
PluginGraph graph = expression.BuildGraph();
graph.Log.AssertFailures();
this._interceptorLibrary.ImportFrom(graph.InterceptorLibrary);
this._pipelineGraph.ImportFrom(图);
}
}

Through reflector i found that with the call to graph.Log.AssertFailures() any exceptions that may have occurred during assembly scanning (that includes the ones that are thrown during assembly.GetExportedTypes() which are the ones that you are referring to) are thrown as one big exception. I havent found anything indicating that this behavior can be somehow switched off. What I found out though is that if you catch the exception, the scanning actually succeeds with any assemblies that it managed to scan. StructureMap cannot actually do anything about exceptions being thrown when calling GetExportedTypes() (which is a framework method) except continue to the next assembly. If you dont mind 'losing' some assemblies just catch the exception and move on.

public void Configure(Action configure)
{
lock (this)
{
ConfigurationExpression expression = new ConfigurationExpression();
configure(expression);
PluginGraph graph = expression.BuildGraph();
graph.Log.AssertFailures();
this._interceptorLibrary.ImportFrom(graph.InterceptorLibrary);
this._pipelineGraph.ImportFrom(graph);
}
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文