File tree Expand file tree Collapse file tree
src/ActiveLogin.Authentication.BankId.Core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ namespace ActiveLogin . Authentication . BankId . Core ;
2+
3+ public interface IStateStorage
4+ {
5+ ValueTask < Guid > WriteAsync ( object value ) ;
6+ ValueTask < bool > TryReadAsync < T > ( Guid key , out T ? value ) ;
7+ ValueTask < T ? > RemoveAsync < T > ( Guid key ) ;
8+ }
Original file line number Diff line number Diff line change 1+ using System . Collections . Concurrent ;
2+
3+ namespace ActiveLogin . Authentication . BankId . Core ;
4+
5+ public class InMemoryStateStorage : IStateStorage
6+ {
7+ private static readonly ConcurrentDictionary < Guid , object > _storage = new ( ) ;
8+
9+ public ValueTask < Guid > WriteAsync ( object value )
10+ {
11+ var key = Guid . NewGuid ( ) ;
12+ _ = _storage . TryAdd ( key , value ) ;
13+ return new ValueTask < Guid > ( key ) ;
14+ }
15+
16+ public ValueTask < T ? > RemoveAsync < T > ( Guid key )
17+ {
18+ return _storage . TryRemove ( key , out var value )
19+ ? new ValueTask < T ? > ( ( T ) value )
20+ : new ValueTask < T ? > ( default ( T ) ) ;
21+ }
22+
23+ public ValueTask < bool > TryReadAsync < T > ( Guid key , out T ? value )
24+ {
25+ if ( _storage . TryGetValue ( key , out var obj ) )
26+ {
27+ value = ( T ) obj ;
28+ return new ValueTask < bool > ( true ) ;
29+ }
30+
31+ value = default ;
32+ return new ValueTask < bool > ( false ) ;
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments