public Object GetScoped(Type ObjectType, string UniqueId) { CancellationTokenSource tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; Object RequestedObject = null; Task SearchObjectTask = Task.Run(() => { var CurrentScopeList = ScopeObjectList.Where(x => x.Key == UniqueId).FirstOrDefault().Value; if (CurrentScopeList != null) { Parallel.ForEach(CurrentScopeList, (x, state) => { if (x.QualifiedName == ObjectType.FullName) { RequestedObject = x.ClassObject; tokenSource.Cancel(); state.Break(); } }); } }, token); token.Register(() => { if (RequestedObject == null) { } }); Task.WaitAll(SearchObjectTask); return(RequestedObject); }
public void InitScopeQueue(string UniqueKey) { Parallel.ForEach(ScopedClassList, ClassName => { Object NewObject = context.GetBean(ClassName, null); if (NewObject != null) { if (!ScopeObjectList.ContainsKey(UniqueKey)) { ScopeObjectList.TryAdd(UniqueKey, new List <InjectionObjects>()); } var CurrentSesstionObjectList = ScopeObjectList.Where(x => x.Key == UniqueKey).FirstOrDefault().Value; if (CurrentSesstionObjectList != null) { CurrentSesstionObjectList.Add(new InjectionObjects { QualifiedName = ClassName, ClassObject = NewObject }); ScopeObjectList.TryAdd(UniqueKey, CurrentSesstionObjectList); } } }); }