简体   繁体   English

我应该如何组织ASP.NET Web API解决方案?

[英]How should i organize my ASP.NET Web API solution?

I'm starting a new ASP.NET Web API project. 我正在启动一个新的ASP.NET Web API项目。 I admit, I have never been good at organizing my projects in my solution. 我承认,我从来都不擅长在解决方案中组织项目。 I want to get better at this, hence the question. 我想对此做得更好,因此是一个问题。

First, the naming convention I plan to use is one I've found several places (blogs, MSDN, etc) and includes the CompanyName.ProductName.Component. 首先,我打算使用的命名约定是我在几个地方(博客,MSDN等)发现的,并且包含CompanyName.ProductName.Component。

My confusion is around the projects within the solution. 我的困惑是解决方案中的项目。 I have the proof of concept for the service working but everything is in one project. 我有服务工作的概念证明,但一切都在一个项目中。 It works but this is bad for a variety of reasons and I want to separate the components. 它可以工作,但是由于多种原因这很糟糕,我想将组件分开。 The project uses EF, interfaces for the data repository, a test project, business objects, and the my Web API controllers. 该项目使用EF,数据存储库的接口,测试项目,业务对象和my Web API控制器。 How should I organize my solution and the various projects? 我应该如何组织我的解决方案和各种项目?

There is no one one-size-fits-all answer for this question. 这个问题没有一个千篇一律的答案。 However this is my default: 但这是我的默认设置:

在此处输入图片说明

Some additional notes: 一些附加说明:

Although the project names for the web, core, and data are [productName].[layer], I change the default namespace and assembly name to be [company].[product].[layer]. 尽管Web,核心和数据的项目名称为[productName]。[layer],但我将默认名称空间和程序集名称更改为[company]。[product]。[layer]。 I don't fully qualify the so that I can keep the path lengths down (The build will complain once you hit 256 characters in a path). 我没有完全限定,所以我可以减小路径长度(一旦在路径中输入256个字符,构建就会抱怨)。

The model project usually has other folders too, such as \\validation, \\exceptions, etc... but I just wanted to illustrate that I usually put the interface for data access along side the model classes. 模型项目通常也有其他文件夹,例如\\ validation,\\ exceptions等...,但我只是想说明一下,我通常将数据访问接口放在模型类旁边。

I do not change the default namespace or assembly name for the test projects because they aren't important to anything outside of the solution. 我不会更改测试项目的默认名称空间或程序集名称,因为它们对解决方案之外的任何内容都不重要。

That being said, if my API is dead simple (only a couple controllers) I might go for one project for the API and one test project. 话虽如此,如果我的API非常简单(只有几个控制器),那么我可能会去一个API项目和一个测试项目。 If I do this, I add folders under the API for each logical layer (core, data, etc...). 如果这样做,我将在API下为每个逻辑层(核心,数据等)添加文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该如何组织我的ASP.Net主题和常见的CSS文件 - How should I organize my ASP.Net themes and common CSS files 使用ASP.net MVC时应如何设置解决方案? - How should I set-up my solution when using ASP.net MVC? ASP.Net Web API与WCF,我应该在我的项目中选择哪一个 - ASP.Net Web API vs WCF, which one should I choose in my project 我如何创建asp.net Web解决方案的用户控件? - How can i create a User control of my asp.net web solution? 有关如何组织我的各种Web项目(rails,asp.net,binaries和git repos)的建议 - Recommendations on how to organize my various web projects (rails, asp.net, binaries and git repos) 如何在ASP .NET Web API中组织Web服务 - How to organize web service in ASP .NET Web API 我应该为ASP.NET MVC和ASP.NET Web API创建单独的模型吗? - Should I create separate models for ASP.NET MVC and ASP.NET Web API? 我应该如何将多个参数传递给 ASP.Net Web API GET? - How should I pass multiple parameters to an ASP.Net Web API GET? 如何在ASP.NET中的UI上组织我的方法[设计问题] - How to organize my methods on the UI in ASP.NET [Design Problem] 我应该如何对ASP.NET网站项目进行版本控制? - How should I version an ASP.NET Web Site project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM