Using singletons in Add-in Express

Add-in Express™ Support Service
That's what is more important than anything else

Using singletons in Add-in Express
 
Vladimir Vajda




Posts: 75
Joined: 2011-05-24
We have developed application which heavily uses dependency injection and Windsor Castle IoC container.
There are a lot of components which are needed to be singleton in excel application. By excel application I mean on excel process and all excel instances running. The problem we have now is that our classes are singleton only to one excel instance. If for example we open 2 excel documents those components will be created per instance, so there will be 2 instances instead of only one. We are creating ribbon bar through Windsor Castle and have some buttons that are enabled and disabled of application context, for example: if user logs in some buttons on ribbon are enabled, and if user opens new excel document, in that new excel all buttons should be enabled since user has logged in already in one excel instance (no need to log in every time he opens new document). There is also some configuration singleton which can be changed by user in run time and should be shared by all excel instances as singleton.
So my question is, is it possible to create classes in add-in so that they become singleton?
How to do that?
And where to find further information about add-in architecture and other documentation about this problem?

Just to say, all my initialization is currently done in AddinModule_OnRibbonBeforeCre ate event, should I do this at some other place?

Best regards,

Vladimir Vajda
Posted 10 Dec, 2011 09:43:04 Top
Andrei Smolin


Add-in Express team


Posts: 16223
Joined: 2006-05-11
Hello Vladimir,

As far as I understand, your user logs in to some app. If my understanding is correct, I'd try to avoid all these problems by querying the application about the user's state. If the user hasn't logged and your server app retuns false, I'd disable the button.

What do you think?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Dec, 2011 10:32:22 Top
Vladimir Vajda




Posts: 75
Joined: 2011-05-24
I want to provide functionality that when user logs in in one excel in our excel addin, it is logged in in all excel documents/windows which are opened as long EXCEL.EXE process is running. I want a few other things to be shared between excel instances, logging in is just one of many where I need singleton functionality.
So is there a way to have singleton that is on excel process level (one for all excels opened), not on excel instance level?
Is addin express instanced once at excel process level, or at excel instance level?
Posted 12 Dec, 2011 15:20:42 Top
Andrei Smolin


Add-in Express team


Posts: 16223
Joined: 2006-05-11
Hello,

To start with, I don't understand your vocabulary.

It is possible to start several EXCEL.EXE processes; each of the processes is an Excel instance. Each Excel instance loads an instance of your add-in; the user opens several workbooks in each of the Excel instances. Then the user uses an instance of your add-ins to log into an app that your add-in is a gate to. Note that the user logs into the app, not into Excel documents. Then, the other add-in instances can check if the user is logged in in an appropriate event, say in WindowActivate.

Note that you talk about "immediate knowing that the user has logged in". I talk about "checking if the user is logged" repeatedly/periodically/at certain moments.

Vladimir Vajda writes:
So is there a way to have singleton that is on excel process level (one for all excels opened), not on excel instance level?


"Singleton" means, in particular, that if I try to create a new object of a certain class from a certain app/system/assembly, I'll be given back an existing instance of that class, not a new class instance. That is, this behavior is the responsibility of that app/system/assembly and not of the add-in that uses that class, would you agree?

I've googled out this article Interprocess Communications.

Vladimir Vajda writes:
Is addin express instanced once at excel process level, or at excel instance level?


An add-in is loaded into every instance of the host application ( = into every EXCEL.EXE process).

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 13 Dec, 2011 03:17:23 Top
Vladimir Vajda




Posts: 75
Joined: 2011-05-24
It is possible to start several EXCEL.EXE processes; each of the processes is an Excel instance. Each Excel instance loads an instance of your add-in; the user opens several workbooks in each of the Excel instances.

This is where problem was, I didn't realize that I can have more than one EXCEL.EXE process. Everything else is than pretty clear.

Thanks Andrei.
Posted 13 Dec, 2011 04:53:53 Top
Andrei Smolin


Add-in Express team


Posts: 16223
Joined: 2006-05-11
You are welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 13 Dec, 2011 05:11:06 Top