public RouteProvider(IConfiguration configuration, IWebHostEnvironment webHostEnvironment) { var fileCache = new LocalJsonFile <RouteInfo>(webHostEnvironment.ContentRootFileProvider, "routes.json"); refreshAction = (force) => { IEnumerable <RouteInfo> routes = null; if (fileCache.CacheExists()) { routes = fileCache.Load().Result; } if (force || routes == null) { routes = new RouteWebProvider(configuration).GetRoutesFromWeb().Result; fileCache.Save(routes); } allRoutes = routes.ToDictionary(info => RouteInfo.GetWebFriendlyName(info.Name)); }; refreshAction(false); }
public RouteInfo Get(string routeName) { return(allRoutes.TryGetValue(RouteInfo.GetWebFriendlyName(routeName), out var routeInfo) ? routeInfo : null); }