我开始尝试 Azure 功能.我正在使用 Visual Studio 2017 预览版 15.3.当我右键单击我创建的 Azure Functions 项目并选择 Add>New Item...>Azure Function 时,Visual Studio 生成的默认模板是 public static class
和 public静态异步任务
方法(函数).
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 函数 - 函数应该写在静态类中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!