public static Func <IContext, HandlerInfo, Task> Get(Type handlerType, string httpMethod) { IDictionary <string, Func <IContext, HandlerInfo, Task> > handlerCache; if (!RunMethodCache.TryGetValue(handlerType, out handlerCache)) { lock (RunMethodCacheCollection.SyncRoot) { if (!RunMethodCache.TryGetValue(handlerType, out handlerCache)) { var asyncRunMethod = new PipelineFunctionFactory(handlerType).BuildAsyncRunMethod(httpMethod); handlerCache = new Dictionary <string, Func <IContext, HandlerInfo, Task> > { { httpMethod, asyncRunMethod } }; RunMethodCache.Add(handlerType, handlerCache); return(asyncRunMethod); } } } // It's not really worth all the locking palaver here, worst case scenario the AsyncRunMethod gets built more than once. Func <IContext, HandlerInfo, Task> method; if (!handlerCache.TryGetValue(httpMethod, out method)) { method = new PipelineFunctionFactory(handlerType).BuildAsyncRunMethod(httpMethod); handlerCache[httpMethod] = method; } return(method); }
public static Func<IContext, HandlerInfo, Task> Get(Type handlerType, string httpMethod) { IDictionary<string, Func<IContext, HandlerInfo, Task>> handlerCache; if (!RunMethodCache.TryGetValue(handlerType, out handlerCache)) { lock (RunMethodCacheCollection.SyncRoot) { if (!RunMethodCache.TryGetValue(handlerType, out handlerCache)) { var asyncRunMethod = new PipelineFunctionFactory(handlerType).BuildAsyncRunMethod(httpMethod); handlerCache = new Dictionary<string, Func<IContext, HandlerInfo, Task>> { {httpMethod, asyncRunMethod} }; RunMethodCache.Add(handlerType, handlerCache); return asyncRunMethod; } } } // It's not really worth all the locking palaver here, worst case scenario the AsyncRunMethod gets built more than once. Func<IContext, HandlerInfo, Task> method; if (!handlerCache.TryGetValue(httpMethod, out method)) { method = new PipelineFunctionFactory(handlerType).BuildAsyncRunMethod(httpMethod); handlerCache[httpMethod] = method; } return method; }