Add support for dependency injection in Excel-DNA
See original GitHub issueI’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:
- Created 8 years ago
- Comments:16 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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 haveAutoOpen
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
It should be very easy to make your own version of ExcelRibbon which is not automatically instantiated.