How to detect install mode in Startup.cs?
# help-with-umbraco
t
Is it possible to detect if Umbraco is currently in install mode when booting up? Our use case is we have a package that assumes the database is already set up, so on a fresh development machine/startup we cannot even start the app to import our example data. If we simply comment out the relevant `.Use`calls in Startup.cs we can move past it, but it would be nice to handle this automatically by checking if we currently are in install mode or not. (Addendum: It's not our package so we cannot change the behavior of the package)
s
If you put it in a Composer in stead (included benefit of not polluting your startup file, thus making it easier to upgrade when Umbraco makes changes to Startup), you can add the RuntimeLevel attribute to define when the composer should run https://docs.umbraco.com/umbraco-cms/implementation/composing#runtime-levels
s
If it's not your package then you have a problem, the package author will need to fix it.
n
And to fully answer the question here if want to get the runtime level manually you can get the runtime state by getting the
IRuntimeState
service from DI. For example from
app.Services.GetRequiredService<MyService>()
Then you can check the
IRuntimeState.Level
to get the current runtime level. For example this could be
RuntimeLevel.Run
which refers to when Umbraco is fully running.
13 Views