问题
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