The App
class
Each QueryStorm project has an App
class that's defined in the App.cs
(or App.vb
) file. This is the entry point of the app.
The constructor
The constructor of the app class receives an appHost
argument which gives the app access to certain services that the host environment (i.e. QueryStorm Runtime) provides.
The services that the Runtime provides are:
- An
IExcelAccessor
which allows accessing the root ExcelApplication
object. - An
IWorkbookAccessor
which allows accessing the current workbook. For workbook apps, this will be workbook that contains the app. For extension apps this will be the active workbook. - An
IShortcutService
which allows registering custom shortcuts. - An
IQueryStormLogger
which allows logging to the log window (runtime) and the messages pane (IDE).
The Start()
method
The Start
method is the place to perform any startup logic for your app. It is called when the app is started. For a workbook app, this will be when the workbook is opened. For an extension app, this will be when Excel starts.
For example, if the app needs to react to a keyboard shortcut, it should put the registration logic in the Start
method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
When overriding the Start
method, it is important to call the base class's Start()
method first. The base class's Start method does the following:
- registers dependencies with the IOC container
- instantiates and starts components
- scans the assembly for a ribbon and context menu commands and registers the ones it finds
The Stop()
method
The stop method is invoked when the app is shutting down. For workbook apps this will be when the workbook is closing. For extension apps this will be when Excel is closing.
Apps should override this method if they have any cleanup to do (e.g. closing connections, disposing of resources).
1 2 3 4 5 6 7 |
|
When overriding the Stop()
method, it is important to call the base class's Stop()
method in the end, since the base class uses it to perform cleanup as well (e.g. unregister context menus and ribbons, dispose of the container).