private T HandleScopedStorageCollision<T>(int id, T value) { ScopedStorage newStorage = new ScopedStorage { Id = id, ScopedService = value }; SpinWait spinWait = new SpinWait(); var initialStorage = InternalScopedStorage; do { var current = initialStorage; newStorage.Next = current; while (!ReferenceEquals(current, ScopedStorage.Empty)) { if (current.Id == id) { return value; } current = current.Next; } if (ReferenceEquals( Interlocked.CompareExchange(ref InternalScopedStorage, newStorage, initialStorage), initialStorage)) { return value; } spinWait.SpinOnce(); initialStorage = InternalScopedStorage; } while (true); }
public AllowedOptionsBuilderTest() { var httpContextStorage = new ScopedStorage <HttpContext> { Value = new DefaultHttpContext { User = new MockPrincipal() } }; this.builder = new AllowedOptionsBuilder <Entity>(httpContextStorage); }
static ScopedStorage() { var empty = new ScopedStorage(); empty.Next = empty; // this is intentional and need so you can make the assumption that Next is never null Empty = empty; }