Azure功能结构 [英] Azure Function Structure

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

问题描述

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



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



以下是我遇到的问题:


  1. 我有.NET Standard 2内置的不错的类库,可以处理我所有的后端需求,即使用Cosmos Db,Azure表存储,Azure SQL,Redis,Azure存储来处理CRUD操作。无论我做什么,我都无法将这些类库集成到Azure Functions项目中。

  2. 此外,事实证明,在Azure Functions项目中获取依赖项注入是一项艰巨的任务-尤其是在上面提到的我的类库中。

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



这似乎与最佳做法背道而驰。那么除了创建整体代码或等到Azure函数支持.NET Core和DI之外,还有什么解决方案?



我想我可以使用来自.NET Standard类的库面向.NET Framework的常规Azure Functions项目。毕竟,.NET Standard的想法是标准化事物。我在这里开设了几则帖子。我正在提供链接,以便您可以看到遇到的问题:






现在n从VS运行时,将使用npm工具,而不是VS软件包随附的旧工具。


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.

Here are the problems I'm running into:

  1. I have nice class libraries built in .NET Standard 2 that handle all my "backend needs" namely handling CRUD ops with Cosmos Db, Azure Table Storage, Azure SQL, Redis, Azure Storage. No matter what I did, I couldn't integrate these class libraries into an Azure Functions project. More details below.
  2. Also, getting dependency injection in Azure Functions project has proven to be quite a task -- especially with my class libraries mentioned above.

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.

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.

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:

Using .NET Core 2.0 Libraries in WebJob Targeting .NET Framework 4.7

No parameterless constructor error in WebJobs with .NET Core and Ninject

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.

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.

解决方案

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:

  • 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]\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\func.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:

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天全站免登陆