Azure 函数 - 函数应该写在静态类中

Azure functions - should functions be written inside static classes(Azure 函数 - 函数应该写在静态类中)
本文介绍了Azure 函数 - 函数应该写在静态类中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始尝试 Azure 功能.我正在使用 Visual Studio 2017 预览版 15.3.当我右键单击我创建的 Azure Functions 项目并选择 Add>New Item...>Azure Function 时,Visual Studio 生成的默认模板是 public static classpublic静态异步任务方法(函数).

I'm starting to try out Azure functions. I'm using Visual Studio 2017 Preview version 15.3. When I right click on the Azure Functions project I created, and select Add>New Item...>Azure Function, the default template Visual Studio generates is of a public static class with a public static async Task method (the function).

该类是否需要是静态的(我将其更改为非静态的,它似乎可以工作)?这是 Azure 函数的最佳实践吗?如果是这样,使用非静态类来保存 Azure Function 方法可能会出现什么问题?

Does the class need to be static (I changed it to non-static and it seems to work)? Is that a best practice for Azure functions? If that is the case, what problems might rise by using a non-static class to hold the Azure Function method?

推荐答案

该类是否需要是静态的(我将其更改为非静态的,它似乎可以工作)?这是 Azure 函数的最佳实践吗?

Does the class need to be static (I changed it to non-static and it seems to work)? Is that a best practice for Azure functions?

静态类只能包含静态成员,不能实例化.将类更改为非静态将允许您添加非静态成员并创建此类的实例.

A static class can only contain static members, and it can't be instantiated. Changing the class to non-static will allow you to add non-static members and create an instance of this class.

请检查您是否需要向此类添加非静态成员或创建此类的实例.由于单一职责原则,即每个类都应对软件提供的单个功能部分负责,我建议您创建一个新类并将非静态成员放在那里.

Please check whether you need to add non-static members to, or create an instance of, this class. Due to the Single Responsibility Principle, which states that every class should have responsibility over a single part of the functionality provided by the software, I suggest you create a new class and put the non-static members there.

如果是这样,使用非静态类来保存 Azure Function 方法可能会出现什么问题?

If that is the case, what problems might rise by using a non-static class to hold the Azure Function method?

我想你想使用非静态类的原因是你想在其中创建一些非静态成员.这样做会使您的类变得复杂且难以维护.

I suppose the reason you want to use a non-static class is that you want to create some non-static members in it. Doing so will make your class complex and difficult to maintain.

我的最终答案是该类可以更改为非静态的.为了保持类简单,我建议你保持类静态.

My final answer is that the class can be changed to non-static. To keep the class simple, I suggest you keep the class static.

这篇关于Azure 函数 - 函数应该写在静态类中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)