我应该在ASP.NET Core项目中的哪里放置自定义类 [英] Where should I put custom classes in ASP.NET Core project
问题描述
我有一些实用程序功能,并希望为这些功能创建名为Utility的类,以便可以在多个控制器中使用这些类功能.
I have some utility functions and want to create classes named Utility for these functions, so that I can use these class function in more than one controllers.
那么我可以在哪里将这些类放在ASP.NET Core 1.1
项目的文件夹结构中,然后如何访问?
So where can I put these class in my folder structure in ASP.NET Core 1.1
project, and how can I access then?
推荐答案
正如@Tseng所提到的,您可以将它们放置在任何位置,但是通常您不希望将它们放置在wwwroot
层次结构中. :-)
As @Tseng mentioned you can place them anywhere but usually you will not want to place them in the wwwroot
hierarchy. :-)
访问它们就像通过名称空间指定它们一样简单,或者包括对它们所在的名称空间使用正确的using语句.我个人将大多数自定义类保留在单独的库项目中,但对于我想要的那些类,请保存在实际的asp.net中核心项目我将它们保存在名为Code
的文件夹中,但是您可以根据自己的项目命名.
Accessing them is as simple as specifying them by namespace or including the right using statement to the namespace they live in. I personally keep most of my custom classes in separate library projects but for the ones I want in the actual asp.net core project I keep them in a folder called Code
, but you can name it whatever feels right for your project.
这是我当前正在从事的项目中的一个示例.它显示了我如何组织Code
文件夹下的子文件夹.
Here is one example from a project I'm currently working on. It shows how I have organized subfolders under the Code
folder.
这篇关于我应该在ASP.NET Core项目中的哪里放置自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!