Created
September 8, 2017 20:31
-
-
Save christopheranderson/0ecbb4cde8483e796cf30b1354ac6fc0 to your computer and use it in GitHub Desktop.
Factory/Singleton pattern in Azure Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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