I have a Web Api based applicaiton. There is a method in an ApiController, which can be called as via Http-request, as via Hangfire handler.
The problem is I need to get a list of paths of files for a particular bundle, however I cannot find a right way how to do that. I have one solution if I have HttpContext:
var httpContext = new HttpContextWrapper(HttpContext.Current);
var reportScripts = registeredBundles.First((b) => b.Path == "~/bundles/report");
BundleContext bundleContext = new BundleContext(httpContext, BundleTable.Bundles, "~/bundles/");
var filePath = reportScripts.EnumerateFiles(bundleContext).First().IncludedVirtualPath;
However, if Hanfire calls my method I don't have HttpContext at all. So the approach above doesn't work. I've found a workaround here and here(just to mock HttpContext). But this solution looks very weird for me... and I would not use it.
Could anybody help me to find a way to get list of paths from a particular bundle? I was surprised why Bundle object has internal field "Items", but not a public one.
More details if my explanation was not clear enough: For example I have a bundle:
bundles.Add(new ScriptBundle("~/bundles/report")
.Include("~/Scripts/d3js/d3.min.js")
.Include("~/Scripts/jquery/jquery-1.12.4.js"));
and I need to get the string "Scripts/d3js/d3.min.js" from there.
This is needed for me, because i render complicated report on the server side and send it to the customer. For the template of the report I need links for some scripts(i.e. Jquery, etc). I don't want to use any constants and hardcode paths to my Scripts, because I can change a version of a script or a file in future. In this case my report silently will be broken. In bundles I will always have up to date versions of the scripts, so if I could take paths from bundles it would be perfect!
Thanks in advance!