解决 Open Generic 依赖关系时 StructureMap 错误
所以我已经像这样在 StructureMap 中连接了我的开放通用插件
scan.ConnectImplementationsToTypesClosing(typeof(IRepository<>));
但仍然会遇到可怕的情况
没有为 PluginFamily KharaSoft.Utils.IRepository`1[[KharaSoft.App.Core.DomainObject, KharaSoft.App.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] 定义默认实例
我在初始化容器后进行调试并看到它确实有一个 RepositoryBase<> 实例注册所以它知道我想要做什么,但它不会为我关闭它。我在这里缺少什么吗?
So I've wired up my open generic plugin in StructureMap like so
scan.ConnectImplementationsToTypesClosing(typeof(IRepository<>));
But still get the dreaded
No Default Instance defined for PluginFamily KharaSoft.Utils.IRepository`1[[KharaSoft.App.Core.DomainObject, KharaSoft.App.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
I debug after the Container is initialized and see that it does indeed have an instance of RepositoryBase<> registered so it knows what I want done, but it won't close it for me. Is there something I'm missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有看到完整的扫描代码或项目布局,就很难进行锻炼。遇到此问题时,我通常会执行一些默认步骤。
确保您已
确保包含存储库类的程序集包含在扫描中:
确保您有正确的实现:
具有匹配
希望此建议中的某些内容可以帮助您找到问题。
It's hard to workout without seeing the full Scan code or your project layout. There are a few default steps I normally go through when I have this issue.
Ensure you have
Ensure that the assembly containing the Repository classes is included in the scan:
Ensure that you have the correct implementations in place:
has matching
Hopefully something amongst this advice might help you find the issue.
所以我不确定这是否是“最好”的方法,但这是我发现有效的方法。我必须像这样显式注册插件的开放实现:
请参阅我不想在所有情况下直接关闭通用。所以现在我的 MVC 控制器可以采用这样的依赖关系
并且 StructureMap 将使用 RepositoryBase 的实例关闭依赖关系
So I'm not sure if this is the "best" way but this is what I found that works. I had to explicitly register the open implementation of the plugin like this:
See I didn't want to close the generic directly in all cases. So now my MVC controller can take a dependency like so
And StructureMap will close the dependency with an instance of RepositoryBase