Where should I put custom classes in ASP.NET Core project [closed]

微笑、不失礼 提交于 2019-12-10 22:22:34

问题


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.

So where can I put these class in my folder structure in ASP.NET Core 1.1 project, and how can I access then?


回答1:


As @Tseng mentioned you can place them anywhere but usually you will not want to place them in the wwwroot hierarchy. :-)

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.

Here is one example from a project I'm currently working on. It shows how I have organized subfolders under the Code folder.



来源:https://stackoverflow.com/questions/43763976/where-should-i-put-custom-classes-in-asp-net-core-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!