Skip to content

Instantly share code, notes, and snippets.

@christopheranderson
Created September 8, 2017 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopheranderson/0ecbb4cde8483e796cf30b1354ac6fc0 to your computer and use it in GitHub Desktop.
Save christopheranderson/0ecbb4cde8483e796cf30b1354ac6fc0 to your computer and use it in GitHub Desktop.
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