Azure functions Azure功能/持久功能/global.asax

Azure functions Azure功能/持久功能/global.asax,azure-functions,Azure Functions,我正在尝试移动一个我已经工作多年的web应用程序。我在global.asax中加载了一个配置列表,以便将来访问。我看到global.asax在持久函数中没有等价物,所以这就是我开始研究持久函数的原因;但我也不确定这是处理货物的最佳方式。在我当前的环境中,可能会加载10000多条记录,因此动态加载它们也不会很好 这是我的global.asax配置的示例;这并不重要…: if (query.Count() > 0) {

我正在尝试移动一个我已经工作多年的web应用程序。我在global.asax中加载了一个配置列表,以便将来访问。我看到global.asax在持久函数中没有等价物,所以这就是我开始研究持久函数的原因;但我也不确定这是处理货物的最佳方式。在我当前的环境中,可能会加载10000多条记录,因此动态加载它们也不会很好

这是我的global.asax配置的示例;这并不重要…:

            if (query.Count() > 0)
            {
                foreach (var item in query)
                {
                    bool bActive = false;
                    bool.TryParse(item.IsActive.ToString(), out bActive);

                    if (item.ProviderName != string.Empty && bActive)
                    {
                        try
                        {
                            bool bEncrypt = false;
                            bool bSign = false;

                            // yes, I know these are bools anyway; this is to catch possible nulls...
                            bool.TryParse(item.Sign.ToString(), out bSign);
                            bool.TryParse(item.Encrypt.ToString(), out bEncrypt);

                            SConfiguration.AddServiceProvider(
                                new ServiceProvider()
                                {
                                    Name = item.PartnerEntity,
                                    NameIDFormat = item.NameFormat,
                                    SignSAMLResponse = bSign,
                                    Sign = bSign,
                                    Encrypt = bEncrypt

                                });
                        }
                   }
因此,这个配置需要通过多个http发送(它是SAML)来持久化


是否有办法预加载配置并使其可用于所有未来的azure函数调用?

您可以将依赖项注入与服务生命周期单例一起使用:

using System;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Http;
using Microsoft.Extensions.Logging;

[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]

namespace MyNamespace
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {

            builder.Services.AddSingleton<ILoggerProvider, MyLoggerProvider>();
        }
    }
}
使用系统;
使用Microsoft.Azure.Functions.Extensions.DependencyInjection;
使用Microsoft.Extensions.DependencyInjection;
使用Microsoft.Extensions.Http;
使用Microsoft.Extensions.Logging;
[程序集:函数启动(typeof(MyNamespace.Startup))]
名称空间MyNamespace
{
公共类启动:函数启动
{
公共覆盖无效配置(IFunctionsHostBuilder)
{
builder.Services.AddSingleton();
}
}
}
资料来源: