开发者

Autofac to Common Service Locator (TypedParameter issue)

开发者 https://www.devze.com 2023-03-12 16:29 出处:网络
How do i modify the following from Autofac to use the Common Service Locator (where _context is of type IComponentContext):

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 someo开发者_如何学Gone could help. Thanks


A TypedParameter provides an additional value to the constructor of the component being resolved. In this case the underlying ContextQuery will accept a parameter of type IContentManager with the value this 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

0

精彩评论

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