Autofac 到通用服务定位器(TypedParameter 问题)
如何修改 Autofac 中的以下内容以使用公共服务定位器(其中 _context 的类型为 IComponentContext):
var query = _context.Resolve<IContentQuery>(TypedParameter.From<IContentManager>(this));
上面的代码取自 Orchard,我正在尝试删除对 Autofac 的依赖。通常我会尝试类似的方法:
var query = ServiceLocator.Current.GetInstance<IContentQuery>();
但是这会返回 null 并且我看不到如何处理 TypedParameter 的东西,因为我不明白它在做什么。
如果有人可以提供帮助,我将非常感激。谢谢
How do i modify the following from Autofac to use the Common Service Locator (where _context is of type IComponentContext):
var query = _context.Resolve<IContentQuery>(TypedParameter.From<IContentManager>(this));
The code above is taken from Orchard and and i'm trying to remove the dependency on Autofac. Usually i'd try something like:
var query = ServiceLocator.Current.GetInstance<IContentQuery>();
However this returns null and i can't see how to handle the TypedParameter stuff as i don't understand what it's doing.
I'd really appreciate it if someone could help. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TypedParameter
为正在解析的组件的构造函数提供附加值。在这种情况下,基础ContextQuery
将接受类型为IContentManager
的参数,并传递值this
。公共服务定位器不支持参数化,因此您可能需要使用底层 IoC 容器的特定功能。
希望这有帮助。
缺口
A
TypedParameter
provides an additional value to the constructor of the component being resolved. In this case the underlyingContextQuery
will accept a parameter of typeIContentManager
with the valuethis
being passed.Common Service Locator doesn't support parameterisation, so you will probably need to use the specific features of your underlying IoC container.
Hope this helps.
Nick