SIF endpoint spins down after some time of inactivity

This is generally acceptable in normal conditions - eg: staging / testing environment are very rarely called and thus IIS perceive the application pool as idle (there's no traffic) then proceeds to spin down the application pool.

There's no code change that can fix this.

The hosting strategy on the other hand can be changed to cater for this need.

Application Pool

IIS ⇨ Application Pool ⇨ [pick application pool to configure] ⇨ Advanced Settings

Configure the following keys with the following values:

Start Mode: set to 'AlwaysRunning'

Idle Time-out: Change to whatever is needed - in the example above - the default value is 20 minutes. Eg: when idling out for 20 minutes, then the action in 'Idle Time-out Action' will be done.

Further investigation into what value goes into this configuration is required and may differ case-by-case, depending on the environment and use case.

Idle Time-out Action: set to 'Suspend'

Application Pool Recycling

Further down the Advanced Setting, there's the application recycling settings that can be tuned to suit different needs.

Summary

As it can be seen here - there's no silver bullet set of configuration that satisfies all scenario of usages.

Different environments require different tuning.