Azure 函数结构 [英] Azure Function Structure

查看:26
本文介绍了Azure 函数结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力思考我们应该如何构建 Azure 函数.

I'm trying to wrap my head around how we're supposed to build Azure functions.

我喜欢构建响应事件的无服务器、紧凑、单一功能的应用程序的想法.

I love the idea of building serverless, compact, single-function apps that respond to events.

以下是我遇到的问题:

  1. 我在 .NET Standard 2 中内置了很好的类库,可以处理我所有的后端需求",即使用 Cosmos Db、Azure 表存储、Azure SQL、Redis、Azure 存储处理 CRUD 操作.无论我做什么,我都无法将这些类库集成到 Azure Functions 项目中.更多详情如下.
  2. 此外,事实证明,在 Azure Functions 项目中进行依赖注入是一项艰巨的任务——尤其是对于我上面提到的类库.

此时,我看到的唯一选择是将代码复制并粘贴"到新的 Azure Functions 项目中,并在没有任何 DI 的情况下使用它.

At this point, the only option I'm seeing is to "copy and paste" code into a new Azure Functions project and use it without any DI.

这似乎与最佳实践"背道而驰.那么除了创建单体代码或等待 Azure Functions 支持 .NET Core 和 DI 之外,还有什么解决方案.

This seems to go against "best practices". So what's the solution other than either to create monolithic code or wait till Azure Functions support .NET Core and DI.

我想我可以使用面向 .NET Framework 的常规 Azure Functions 项目中的 .NET Standard 类库.毕竟,.NET Standard 的想法是标准化"事物.我在这里开了几篇关于 SO 的帖子.我提供了链接,以便您可以查看我遇到的问题:

I thought I could use my .NET Standard class libraries from a regular Azure Functions project targeting .NET Framework. After all, the idea of .NET Standard is to "standardize" things. I opened a couple of posts here on SO. I'm providing the links so that you can see the issues I've run into:

使用 .NETWebJob Targeting .NET Framework 4.7 中的核心 2.0 库

WebJobs 中没有无参数构造函数错误.NET Core 和 Ninject

附言我以前的帖子是指 WebJobs.这是 B 计划方法,因为在支持 .NET Core 和 DI 之类的东西时,WebJobs 似乎比 Azure Functions 领先了半步.最后,我想构建一些 Azure Functions 来使用我在 .NET Standard 2 中构建的类库.

P.S. My previous posts are referring to WebJobs. That was plan B approach because WebJobs seem half a step ahead of Azure Functions when it comes to supporting things like .NET Core and DI. Ultimately, I'd like to build a few Azure Functions that can use my class libraries built in .NET Standard 2.

此外,我之前的帖子提到我的类库面向 .NET Core 2.0.从那时起,我将它们转换为 .NET Standard 2,这根本不需要太多.我这样做是为了真正符合 .NET Standard 2.

Also, my previous posts mention that my class libraries target .NET Core 2.0. Since then I converted them to .NET Standard 2 which didn't really take much at all. I did this so that I truly conform to .NET Standard 2.

推荐答案

一个问题是 Visual Studio 有一个过时的 Functions Core 工具版本.在此问题得到解决之前,您可以通过以下方式解决:

One issue is that Visual Studio has an outdated version of the Functions Core tools. Until this is resolved, you can work around in the following way:

  • 通过运行 npm install -g azure-functions-core-tools
  • 通过 npm 安装最新版本
  • 在 VS 中的 Function App 中,转到属性"
  • 转到调试",然后单击配置文件"下的新建..."
  • 将新配置文件命名为 FunctionsNpm 之类的名称
  • 将可执行文件设置为(替换 [YourUserName]):C:Users[YourUserName]AppDataRoaming pm ode_modulesazure-functions-core-toolsinfunc.exe
  • 将参数设置为 host start
  • 设置工作目录为$(TargetDir)
  • 在工具栏中,查找绿色三角形图标,将您当前的个人资料更改为您刚刚创建的个人资料:
  • Install the latest via npm by running npm install -g azure-functions-core-tools
  • In your Function App in VS, go to the Properties
  • Go to Debug, and click New... under Profile
  • Name the new Profile something like FunctionsNpm
  • Set the executable to (replace [YourUserName]): C:Users[YourUserName]AppDataRoaming pm ode_modulesazure-functions-core-toolsinfunc.exe
  • Set the arguments to host start
  • Set the working directory to $(TargetDir)
  • In toolbar, look for the green triangle icon to change your current Profile to the one you just created:

现在,当您从 VS 运行时,您将使用 npm 工具,而不是 VS 包附带的旧工具.

Now when you run from VS, you'll be using the npm tools instead of the older one that come with the VS package.

这篇关于Azure 函数结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆