开发者

StructureMap 2.6.1.0 Assembly scanning issue

开发者 https://www.devze.com 2023-01-08 01:06 出处:网络
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.

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开发者_StackOverflow社区'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();
    });
});


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); } }

0

精彩评论

暂无评论...
验证码 换一张
取 消