我应该在ASP.NET Core项目中的哪里放置自定义类 [英] Where should I put custom classes in ASP.NET Core project

查看:231
本文介绍了我应该在ASP.NET Core项目中的哪里放置自定义类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些实用程序功能,并希望为这些功能创建名为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屋!

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