Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top