I am dealing with a issue where I am trying to instantiate a shared resource in a Selenium SpecFlow project. The resource is a pool of logins (Dictionary<Login, DateTime>).
Constraint 1: The application is not designed to be logged into concurrently with more than on login at a time. That said, many different users can log in at the same time, but the same users should not log in concurrently at the same time. So the items of the dictionary need to be limited to one thread at a time.
Constraint 2: There is no dependency injection on the project, and I am looking for the equivalent of an application state event.
Note 1: I am coming from a MVC ASP.NET background, and would do something like the global.asax App_Start() method.
Note 2: I will be accessing my Dictionary from the Step Definitions to 'reserve' logins, as well as from the hooks to 'release' the logins.
Is there anything like this in Specflow?
Thanks Devin
UPDATE 9/24/2020:
I've worked on this problem some more, and am deciding to go with a Singleton class. The Singleton is not instantiated until it is first called, then will only instantiate a single instance.
UPDATE 9/24/2020 #1:
I found a caveat to using the Singleton pattern, the issues is that our Specflow project is configured for 'Parallel Execution with Memory Isolation', meaning you cannot share state between threads, and this seems like the recommend way according to Specflow. I found this out the hard way, when I found I was getting 25 unique instances of my Dictionary<Login, DateTime>.
That being said, I am not sure if even I did implement a DI framework, that it wouldn't have the same issue.
I am looking to other forms of persistent storage now, likely going to try Azure Storage Tables.
Ref: Singleton pattern - https://csharpindepth.com/articles/singleton
Ref: Specflow Parallel Execution with Memory (AppDomain) Isolation - https://docs.specflow.org/projects/specflow/en/latest/Execution/Parallel-Execution.html#parallel-execution-with-memory-appdomain-isolation