简体   繁体   English

C#解决方案 - 有多少个项目?

[英]C# Solution - How many projects?

I googled this a little but couldn't find a good result. 我用谷歌搜索了一下但是找不到好结果。

Right now I'm building a web site and I'm trying to make it as correct as possible from a design point of view from the beginning. 现在我正在建立一个网站,我试图从设计的角度来看它尽可能正确。

The problem I'm now facing is that when deciding to start with logging I needed a project to place this code in. As I could not find a suitable place in my currect projects I thought: hey, why not a logging class library? 我现在面临的问题是,当决定开始记录时,我需要一个项目来放置这些代码。由于我在我的当前项目中找不到合适的位置,我想:嘿,为什么不是一个日志类库?

Is there a general guideline on how many projects you should have? 您应该拥有多少个项目的一般准则? I know this would be a rather small project but it would be nice to entirely get it out of my way! 我知道这将是一个相当小的项目,但完全让它脱离我的方式会很好!

Any hints are appreciated :) 任何提示都很赞赏:)

Absolutely you should have a logging library. 你绝对应该有一个日志库。 And if you're going to make this as 'correct as possible from a design point of view' and your proect is less than trivial then you should definitely have some number of projects. 如果你要从设计的角度来看这个'尽可能正确'并且你的预测不是那么简单,那么你肯定应该有一些项目。 The thing is, we have no idea what you're working on besides the fact that it's a web app. 问题是,我们不知道你在做什么,除了它是一个网络应用程序。 It's the biz domain that often determines how complex your solution has to be. 这是商业领域,通常决定了您的解决方案的复杂程度。

I'd go for a three-tier architecture for a small project. 我会为一个小项目寻找一个三层架构。

This would include: 这将包括:

  1. Application Layer 应用层
  2. Business Layer 业务层
  3. Data Layer 数据层

but if you want to add logging, it would be best to create another project. 但是如果要添加日志记录,最好创建另一个项目。 This would also help you so that if you want to add logging to another application, you can just include the logging project. 这也可以帮助您,如果您想将日志记录添加到另一个应用程序,您可以只包括日志记录项目。

Either way would work, if you are concerned about project limit in a solutions. 如果您担心解决方案中的项目限制,则无论哪种方式都可行。 Don't be. 不要。

I myself would put it in a separate project or a utility project. 我自己会把它放在一个单独的项目或实用程序项目中。

We have a solution with 200+ projects. 我们有200多个项目的解决方案。 The downside is long load time in Visual Studio. 缺点是Visual Studio中的加载时间很长。 But past that the only issue is making sure you have enough RAM. 但过去,唯一的问题是确保你有足够的内存。

Also, MSBuild.exe has built-in support for SLN files, so look into using that instead of Visual Studio if you are doing automated builds. 此外, MSBuild.exe内置了对SLN文件的支持,因此如果您正在进行自动构建,请考虑使用它而不是Visual Studio。

"That which changes together should be packaged together", I forget where that guideline comes from (Code Complete maybe?). “那些一起变化的东西应该打包在一起”,我忘记了该指南的来源(代码完成可能?)。

In other words your assemblies (projects) should represent a coherent abstraction in the same way your classes/objects do at a lower level. 换句话说,您的程序集(项目)应该以类/对象在较低级别执行的方式表示连贯的抽象。

So yes, a separate logging project is the right way to go (although do check out log4net or Microsoft's logging block before you roll your own!) 所以,是的,一个单独的日志记录项目是正确的方法(虽然在你自己推出之前检查log4net或微软的日志块!)

Put a logging into a separate project is perfectly fine.However it really depends on the scope of your project.I normally setup my project like this 将日志记录放入一个单独的项目是完全正常的。但是它真的取决于你的项目的范围。我通常设置我的项目这样

YourProject.Web(web project) YourProject.Web(网络项目)

YourProject.Core(all the business logic) YourProject.Core(所有业务逻辑)

YourProject.Web.Tests(Watin tests) YourProject.Web.Tests(Watin测试)

YourProject.Web.Core.UnitTests(Unit tests) YourProject.Web.Core.UnitTests(单元测试)

YourProject.Web.Core.IntegrationTests(Integration tests) YourProject.Web.Core.IntegrationTests(集成测试)

I suggest you to download some open source Project from asp.net to see how the project have been organized. 我建议你从asp.net下载一些开源项目,看看项目是如何组织的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM