Do I need to keep this file in App_Data folder?
That is entirely up to your intended use of the file. If it is static data or configuration that rarely changes, you could store it with your project and set up your project to copy it to the build folder. This can be done in Visual Studio 2019 by selecting "Always Copy" or "Copy if Newer" as the Copy to Output Directory
option., or in the .csproj
file directly.
Can I use the HttpContextAccessor in the business layer constructor and read the content?
You can, by registering it with .Add<Transient|Scoped|Singleton>()
in your Starup.ConfigureServices
. Note that this make it difficult to use this business layer service in a non-request context (e.g. with a scheduled task).
However, if the file is on the same machine as the app, I don't see why you would need the HttpContext
to read it. All you need is the System.IO
and System.Text.Json
namespaces.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…