Skip to content

Instantly share code, notes, and snippets.

@madskristensen
Last active November 7, 2024 13:10

Revisions

  1. madskristensen revised this gist Sep 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ImportMefComponent.cs
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ public class ExtensionPackage : Package
    protected override void Initialize()
    {
    base.Initialize();
    this.SatisfyImportsOnce();
    this.SatisfyImportsOnce(); // This calls the extension method

    ITableManager errorsTable = _tableManagerProvider.GetTableManager(StandardTables.ErrorsTable);
    }
  2. madskristensen created this gist Sep 30, 2015.
    17 changes: 17 additions & 0 deletions ImportMefComponent.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    using System.ComponentModel.Composition;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Shell.TableManager;

    public class ExtensionPackage : Package
    {
    [Import]
    private ITableManagerProvider _tableManagerProvider;

    protected override void Initialize()
    {
    base.Initialize();
    this.SatisfyImportsOnce();

    ITableManager errorsTable = _tableManagerProvider.GetTableManager(StandardTables.ErrorsTable);
    }
    }
    21 changes: 21 additions & 0 deletions SatisfyImportExtensionMethod.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    using System.ComponentModel.Composition;
    using Microsoft.VisualStudio.ComponentModelHost;
    using Microsoft.VisualStudio.Shell;

    public static class MefExtensions
    {
    private static IComponentModel _compositionService;

    public static void SatisfyImportsOnce(this object o)
    {
    if (_compositionService == null)
    {
    _compositionService = ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel)) as IComponentModel;
    }

    if (_compositionService != null)
    {
    _compositionService.DefaultCompositionService.SatisfyImportsOnce(o);
    }
    }
    }