question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for dependency injection in Excel-DNA

See original GitHub issue

I’d like to be able to setup my IoC container via an entry-point of the add-in (my understanding is that the AutoOpen of a class implementing IExcelAddIn will be the very first thing to run when Excel loads the add-in)

public class AddIn : IExcelAddIn
{
    public void AutoOpen()
    {
        // Setup my IoC container
        myContainer.Register<AwesomeService>.As<IMyService>();
        myContainer.Register<GreatLogger>.As<ILog>();
    }
}

And then be able to have dependency resolution on any of my Ribbons in the add-in, ideally via constructor injection (*).

[ComVisible(true)]
public class ModelingRibbon : ExcelRibbon
{
    public ModelingRibbon(IMyService service, ILog logger)
    {
        // ...
    }
}

(*) Not sure if constructor injection would not be possible… Looks like the Ribbon instance is constructed before the AutoOpen runs, which would invalidate the idea of setting up the container in the AutoOpen.


Anyway, goal is to have an entry point that allows the opportunity to setup an IoC container, and have dependency resolution across the different instances created by the framework.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
robodude666commented, Jun 14, 2020

@augustoproiete I see from the MVVM point of view you’d want access to the IRibbonUI.

While doing some further research I ran across VSTOContrib which has a very interesting take on VSTO + IoC.

I suspect it would be possible to create all of your ExcelFunctions (and other Ribbon elements) as ViewModel classes. Then have AutoOpen programmatically create ExcelFunctions for each of your ViewModels that need 'em.

I’ll dink around for a bit and see what I come up with 😄.

-robodude666

0reactions
govertcommented, Nov 1, 2016

It should be very easy to make your own version of ExcelRibbon which is not automatically instantiated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My First Custom Excel-DNA Add-In (dotnet6 edition)
Extensions support for dependency injection, configuration, and for logging, which should be an easy way to hook up to your app settings, plus ......
Read more >
c# - Dependency Injection inside Excel VSTO and Ninject. ...
I'm trying to configure DI for an Excel VSTO project. The generated code-behind for a given worksheet offers me a event called Startup,...
Read more >
Unit Tests: ExcelAsyncUtil has not been initialized
Is there some dependency that I need in my unit testing project or some initialization ... Add support for dependency injection in Excel-DNA....
Read more >
ExcelDna.Registration 1.6.0
Excel-DNA Registration is an extension package for Excel-DNA, adding custom registration processing. This package adds additional transformations appropriate to ...
Read more >
Installing Your Add-in
Excel-DNA supports add -in projects that target . ... These packed addins contain all the required dependencies and can be opened on another...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found