title: Visual Studio Extension, Passing objects from VSPackage to IOleCommandTarget
body: <p>I have created an object that uses the DTE to access files in a Visual Studio Solution and parse them to extract information to drive new features I am implementing.  This object also uses DTE Events to detect when the contents of the Solution changes.  For this reason the object is scoped in the VSPackage.  However, I need the information the object collects inside a IOleCommandTarget where the features are implemented.  I have tried looking for a way to pass this object from the VSPackage to the IOleCommandTarget but so far I have come up empty.  I have tried scoping the object in the IOleCommandTarget but this does not work because the DTE events will not trigger due to the scope or Garbage Collection, I think.</p>
  
  <p>Here is my IOleCommandTarget provider:</p>
  
  <pre><code>internal class VerilogCommandAndControlHandlerProvider : IVsTextViewCreationListener
  {
      [Import]
      internal IVsEditorAdaptersFactoryService AdapterService = null;
      [Import]
      internal ICompletionBroker CompletionBroker { get; set; }
      [Import]
      internal SVsServiceProvider ServiceProvider { get; set; }
  
      public void VsTextViewCreated(IVsTextView textViewAdapter)
      {
          ITextView textView = AdapterService.GetWpfTextView(textViewAdapter);
          if (textView == null)
              return;
  
          DTE dte = ((DTE)ServiceProvider.GetService(typeof(DTE)));
  
          Func&lt;VerilogCommandAndControlHandler&gt; createCommandHandler = delegate () { return new VerilogCommandAndControlHandler(textViewAdapter, textView, dte, this); };
          textView.Properties.GetOrCreateSingletonProperty(createCommandHandler);
      }
  
  }
  </code></pre>