I'm writing an html helper that will do some calculations for me. Now because it is a helper it is a static method. For example:
public class MyHelper
{
public static HtmlString DoSomething()
{
//do some action and return;
}
}
The problem I am facing is that I am calling this from the cshtml file I need to somehow calculate the file version inside this method. Typically I can call this in html with <asp-apend-verion="true">
but because I'm returning a string here it doesn't work if I just type it out.
Based on the research I've done I found out I can do the same thing with IFileVersionProvider.AddFileVersionToPath
, however I can't figure out how to inject it so I can use it inside that method.
Edit:
I think I may need to provide more clear of a picture. Essentially I'm trying to make it so that when I'm debugging code, my javascript files give me full versions of the file and when in production they give me minified versions. As such, I have a modified version of the helper class I found online https://gist.github.com/mohamedmansour/cd50123f8575daba7a7f12847b12da5d to do that for me. My code is a bit different as i want some other things. One of those things is I want to still append file version. So I essentially call this from HTML file. If I just add <asp-append-verion="true">
then it doesn't work as this is parsed as a string. So I need to append the verison before I return that string. I found that I can do that via IFileVersionProvider but i need the implementation of that method in order to use it. This is my only bottleneck.
Edit 2:
My current solution is to create a static property in startup class and then inject it inside the Configure method. Then I can call it from anywhere. Wondering if there is a better solution?