1. <small id='kfHlT'></small><noframes id='kfHlT'>

      <legend id='kfHlT'><style id='kfHlT'><dir id='kfHlT'><q id='kfHlT'></q></dir></style></legend>

        <bdo id='kfHlT'></bdo><ul id='kfHlT'></ul>

      <i id='kfHlT'><tr id='kfHlT'><dt id='kfHlT'><q id='kfHlT'><span id='kfHlT'><b id='kfHlT'><form id='kfHlT'><ins id='kfHlT'></ins><ul id='kfHlT'></ul><sub id='kfHlT'></sub></form><legend id='kfHlT'></legend><bdo id='kfHlT'><pre id='kfHlT'><center id='kfHlT'></center></pre></bdo></b><th id='kfHlT'></th></span></q></dt></tr></i><div id='kfHlT'><tfoot id='kfHlT'></tfoot><dl id='kfHlT'><fieldset id='kfHlT'></fieldset></dl></div>
      <tfoot id='kfHlT'></tfoot>

        获取 Azure Function App v2 的根目录

        时间:2023-10-05
      1. <small id='RDzU1'></small><noframes id='RDzU1'>

            <legend id='RDzU1'><style id='RDzU1'><dir id='RDzU1'><q id='RDzU1'></q></dir></style></legend>
                <bdo id='RDzU1'></bdo><ul id='RDzU1'></ul>
                • <tfoot id='RDzU1'></tfoot>
                    <tbody id='RDzU1'></tbody>
                • <i id='RDzU1'><tr id='RDzU1'><dt id='RDzU1'><q id='RDzU1'><span id='RDzU1'><b id='RDzU1'><form id='RDzU1'><ins id='RDzU1'></ins><ul id='RDzU1'></ul><sub id='RDzU1'></sub></form><legend id='RDzU1'></legend><bdo id='RDzU1'><pre id='RDzU1'><center id='RDzU1'></center></pre></bdo></b><th id='RDzU1'></th></span></q></dt></tr></i><div id='RDzU1'><tfoot id='RDzU1'></tfoot><dl id='RDzU1'><fieldset id='RDzU1'></fieldset></dl></div>

                  本文介绍了获取 Azure Function App v2 的根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我构建了一个 Azure Function App (v2).所有功能所需的配置任务都在一个结构如下的 Setup 类中完成:

                  I build an Azure Function App (v2). Configuration tasks necessary for all functions are done in a Setup class that is structured like the following:

                  [assembly: WebJobsStartup(typeof(Startup))]
                  
                  internal class Startup : IWebJobsStartup
                  {
                    public void Configure(IWebJobsBuilder builder)
                    {
                      Configuration = new ConfigurationBuilder()
                                        .SetBasePath(<functionAppDirectory>)
                                        .AddJsonFile("local.settings.json")
                                        .Build();
                      builder.AddDependencyInjection(ConfigureServices);  
                    }
                  
                    public IConfiguration Configuration { get; set; }
                  
                    private void ConfigureServices(IServiceCollection services)
                    {
                      var connection = Configuration.GetConnectionString("<myconnection-string>");
                      ...
                    }
                  }
                  

                  ConfigureServices 我想从配置文件中读取一个连接字符串.为此,函数应用基本文件夹已使用 SetBasePath 指定.但我发现没有办法访问这条路径.根据 https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function 可以将 ExecutionContext 注入到包含路径的函数中需要.但是如何在我的 Startup 类中访问 ExecutionContext?

                  In ConfigureServices I want to read a connection string from a configuration file. For that the function app base folder has be specified with SetBasePath. But I found no way to get access to this path. According to https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function an ExecutionContext can be injected in a function, which contains the path need. But how do I access ExecutionContext in my Startup class?

                  推荐答案

                  你可以在你的启动文件中使用这段代码.我今天刚刚为我的项目测试了它,它适用于云和本地.

                  You can use this piece of code in your startup file. I have just tested it today for my project and it works on both cloud and local.

                  var executioncontextoptions = builder.Services.BuildServiceProvider()
                      .GetService<IOptions<ExecutionContextOptions>>().Value;
                  var currentDirectory = executioncontextoptions.AppDirectory;
                  

                  这篇关于获取 Azure Function App v2 的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Azure Functions:仅为新事件配置 blob 触发器 下一篇:从 Azure 函数中的 local.settings.json 读取自定义设置

                  相关文章

                    <bdo id='lEyt3'></bdo><ul id='lEyt3'></ul>
                • <small id='lEyt3'></small><noframes id='lEyt3'>

                      <legend id='lEyt3'><style id='lEyt3'><dir id='lEyt3'><q id='lEyt3'></q></dir></style></legend>
                      <tfoot id='lEyt3'></tfoot>
                      <i id='lEyt3'><tr id='lEyt3'><dt id='lEyt3'><q id='lEyt3'><span id='lEyt3'><b id='lEyt3'><form id='lEyt3'><ins id='lEyt3'></ins><ul id='lEyt3'></ul><sub id='lEyt3'></sub></form><legend id='lEyt3'></legend><bdo id='lEyt3'><pre id='lEyt3'><center id='lEyt3'></center></pre></bdo></b><th id='lEyt3'></th></span></q></dt></tr></i><div id='lEyt3'><tfoot id='lEyt3'></tfoot><dl id='lEyt3'><fieldset id='lEyt3'></fieldset></dl></div>