none
Best place to bootstrap Dependency Injection kernel RRS feed

  • Question

  • Hello,

    I am supporting a VSTO Excel AddIn, and I'd like to find out the best place to bootstrap our Dependency Injection Kernel (Ninject).

    For instance, the best place I could find so far is when the ribbon(s) are created, because this happens before the Startup event, if you can believe that.

    We'll initialize our object graph at that point and inject into the ribbon itself, and places in the AddIn itself, with appropriate separations of concerns.

    Is there an event that happens before that that we could monitor?

    Thanks...

    Regards,

    Michael

    Wednesday, December 26, 2012 12:49 AM

Answers

  • I ended up registering the DI Kernel in a C# property. It calculates when it needs to and not a moment sooner, so when I use it to inject the ribbon instance(s), and later the addin on Startup, I have the same Kernel.
    • Marked as answer by mwpowellhtx Wednesday, December 26, 2012 1:42 PM
    Wednesday, December 26, 2012 1:42 PM
  • For edification, I ended up "bootstrapping" my DI Kernel in a property that, when gets for the first time, initializes itself. I access it through the overload:

    protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
      throw new NotImplementedException();
    }
    

    Saturday, July 13, 2013 4:44 PM

All replies

  • Hi mwpowellhtx,

    The Startup event is raised after the add-in is loaded and all the initialization code in the assembly has been run. If you want to add codes before Startup event, you should override the RequestComAddInAutomationService of your add-in. For more information, you can refer to the following link :

    Events in Office Projects :http://msdn.microsoft.com/en-us/library/vstudio/7xy91eax.aspx

    Thanks

    Wednesday, December 26, 2012 3:28 AM
  • It would seem CreateRibbonExtensibilityObject happens even sooner than that.
    Wednesday, December 26, 2012 12:56 PM
  • I ended up registering the DI Kernel in a C# property. It calculates when it needs to and not a moment sooner, so when I use it to inject the ribbon instance(s), and later the addin on Startup, I have the same Kernel.
    • Marked as answer by mwpowellhtx Wednesday, December 26, 2012 1:42 PM
    Wednesday, December 26, 2012 1:42 PM
  • For edification, I ended up "bootstrapping" my DI Kernel in a property that, when gets for the first time, initializes itself. I access it through the overload:

    protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
      throw new NotImplementedException();
    }
    

    Saturday, July 13, 2013 4:44 PM