Feature Builder: SVsServiceProvider missing on IQueryStatusStrategy RRS feed

  • Question

  • I tried to apply context aware visibility on a LaunchPoint. On my experience with VSX I looked around for a BeforeQueryStatus alike method. I found the QueryStatusStrategy and this looked as the hook I was looking for. Using a strategy sounded right. So, made a class in the lib project implementing the IQueryStrategy and created a file with the partial implementation of the LaunchPoint overriding the QueryStrategy property getter/setter. Everything works as expected.

    VsLaunchPoint code:

     public partial class VsLaunchPointDynamic : VsLaunchPoint
       private IQueryStatusStrategy _QueryStatusStrategy;
       protected override IQueryStatusStrategy QueryStatusStrategy
         get {return _QueryStatusStrategy;}
            if (value is DefaultQueryStatusStrategy && _QueryStatusStrategy == null)
              _QueryStatusStrategy = new OnlyVisibleOnConfigQueryStrategy();
            base.QueryStatusStrategy = value;

    Though, I had some difficulties with implementing the strategy, in that means: I wanted to import the SVsServiceProvider from the MEF context but was not available. Something went wrong with the wiring but I can't place it.

    For now, during the execution I can call up the container and resolve the serviceprovider but I realy would like the import to work.

     public class OnlyVisibleOnConfigQueryStrategy : IQueryStatusStrategy
       public SVsServiceProvider ServiceProvider { get; set; }
       public QueryStatus QueryStatus(IFeatureExtension feature)
         //ServiceProvider not available: so use the global service from the Package to fetch the container and
         //initialize the serviceprovider via the container
         var componentModel = Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel;
         ServiceProvider = componentModel.GetService<SVsServiceProvider>();

    I would appreciate if someone could give me a hint on how to wire this up.

    Thanks in advance,


    Thursday, February 17, 2011 1:03 PM


  • I was a bit to fast on this topic, though I don't think it can harm to work out the solution. As mentioned the wiring was not compleet: the Strategy itself was not exported, thus MEF wasn't able to import the dependencies.

    What I did to resolve this:

    1. Exported the strategy to MEF

    [Export("OnlyVisibleOnConfigQueryStrategy", typeof(IQueryStatusStrategy))]
    public class OnlyVisibleOnConfigQueryStrategy : IQueryStatusStrategy

    2. Import it via the LaunchPoint

    [Import("OnlyVisibleOnConfigQueryStrategy", typeof(IQueryStatusStrategy))]
    public IQueryStatusStrategy OnlyVisibleOnQueryStatusStrategy{get;set;}

    Now MEF is able to import the SVsServiceProvider in the strategy. Problem solved.


    • Marked as answer by Jan Kinable Thursday, February 17, 2011 1:35 PM
    Thursday, February 17, 2011 1:33 PM