Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Factory/Singleton pattern in Azure Functions
public class StartUpWork {
private static StartUpWork _singleton;
private string initializeOnce;
public StartUpWork() {
// Do long startup tasks/create database connection pools/whatever you want to happen once
this.initializeOnce = "Woooooo!";
}
public static StartUpWork ensureStartUp() {
if(StartUpWork._singleton == null) {
StartUpWork._singleton = new StartUpWork();
}
return StartUpWork._singleton;
}
}
public static void Run(HttpWebRequest req) {
StartUpWork.ensureStartUp();
// Do the rest of your thing/access properties on StartUpWork
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment