internal object GetInstance(Type type, Scoped scope) { Func <Scoped, object> func = _getInstanceCache.Get(type); if (func == null) { func = _dependencyGraph.GetResolvedFactory(type) !; _getInstanceCache.Add(type, func); } return(func(scope)); }
internal void MethodInject(object instance, Scoped scope) { Type type = instance.GetType(); Action <Scoped, object> action = _injectionCache.Get(type); if (action == null) { action = GenerateMethodInjector(type); _injectionCache.Add(type, action); } action(scope, instance); }
public void AddAndGet() { var testCases = new List <(ReferenceInt input, object output)>(); for (var i = 0; i < 100; i++) { testCases.Add((new ReferenceInt(i), new object())); } var dic = new ThreadSafeDictionary <ReferenceInt, object>(); var tester = new ThreadSafetyTester <(ReferenceInt input, object expectedOutput)>(() => testCases); tester.Test(testCase => { dic.Add(testCase.input, testCase.expectedOutput); object output = dic.Get(testCase.input); Assert.Equal(testCase.expectedOutput, output); }); Assert.Equal(testCases.Count * tester.TaskCount, dic.Count); }