基本应用组织 +发布(.NET 4.0)
我正在努力找出让我的计划井井有条的最佳方法。目前,我在一个项目文件中有许多类文件,但其中一些类执行的操作非常不同,有些类我希望将来向其他应用程序公开。我必须组织我的应用程序的一个想法是创建多个项目文件,其中一个“主”项目将根据需要与所有其他项目及其相关类进行交互。这有道理吗?
我想知道是否有人对在一个解决方案中使用多个项目文件有任何建议(以及如何创建这样的东西?),以及在一个解决方案中拥有多个命名空间是否有意义......
干杯 ----编辑如下----
对不起,我的错。目前我的程序都在一个控制台项目中。在这个项目中,我有几个类,其中一些类基本上启动了一个BackgroundWorker并运行一个无限循环来提取数据。然后,BackgroundWorker 根据需要将此数据传递回主要业务逻辑。我希望将这些数据拉取材料(包括后台工作人员材料)分离到一个项目文件中,并将其余业务逻辑分离到另一个项目文件中。不过,这些项目必须在彼此之间传递对象(数据到主要业务逻辑,业务逻辑将启动参数传递到 dataPull 项目)...希望这会增加更多细节。
I'm trying to figure out the best way to keep my program organized. Currently I have many class files in one project file, but some of these classes do things that are very different, and some I would like to expose to other applications in the future. One thought I had to organizing my application was to create multiple project files, with one "Main" project, which would interact with all the other projects and their relevant classes as needed. Does this make sense?
I was wondering if anyone had any suggestions in regards to using multiple project files in one solution (and how do you create something like this?), and if it makes sense to have multiple namespaces in one solution...
Cheers
----Edit Below----
Sorry, my fault. Currently my program is all in one console project. Within this project I have several classes, some of which basically launch a BackgroundWorker and run an endless loop pulling data. The BackgroundWorker then passes this data back to the main business logic as needed. I'm hoping to seperate this data pull material (including the background worker material) into one project file, and the rest of the business logic into another project file. The projects will have to pass objects between eachother though (the data to the main business logic, and the business logic will pass startup parameteres to the dataPull project)... Hopefully this adds a bit more detail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,您可以在一个解决方案中拥有多个项目文件。您所要做的就是(我假设您正在使用 Visual Studio)向现有解决方案添加一个或多个新项目。
您需要确定解决方案中的哪个项目是您的“主”项目,可以通过右键单击“解决方案资源管理器”中的项目并选择“设置为启动项目”来完成此操作。一般来说,启动项目将包含应用程序的用户界面。
您需要确保主项目引用其他项目 - 正如 @driis 提到的,您可以通过“添加引用”对话框执行此操作,然后单击“项目”选项卡。
为了组织您的项目,您应该考虑应用程序的不同功能区域。通常,应用程序被分为表示、业务逻辑和数据访问组件,但这不是唯一的方法。您可能希望在未来的项目中重用各种方法和类,因此您可能会创建一些“实用程序”或“帮助程序”库。
您可以按照与项目名称相同的方式选择名称空间,或应用程序的其他不同功能区域。有关一般指导,请查看这篇 MSDN 文章 或这个。
祝你好运!
Of course you can have multiple project files in a single solution. All you have to do (and I am assuming you are using Visual Studio) is add one or more new projects to the existing solution.
You need to decide which of the projects in the solution is your "Main" project and you do this by right-clicking on the project in Solution Explorer and choosing "Set as Startup project". Generally speaking, the startup project will be the one that contains the user interface for your application.
You need to make sure that the main project references the other projects - as @driis has mentioned, you do this through the Add Reference dialog and click the "Projects" tab.
To organize your project, you should think about the different functional areas of the application. Usually, an application is divided up into presentation, business logic and data access components, but this is not the only approach. You might have various methods and classes that you want to re-use in future projects, so you might create some "Utility" or "Helper" libraries.
You can choose your namespaces along the same lines as the project names, or other different functional areas of the application. For general guidance, check out this MSDN article or this one.
Good luck!
是的。如果您正在构建一些不平凡的东西,那么多个项目和多个命名空间都非常有意义。
您关于在一个项目中拥有通用功能并可以在其他解决方案中重用的想法是一个很好的想法。这一切都与代码重用和关注点分离有关。
要使用主项目中其他项目的类型,您应该使用“添加引用”对话框添加对所需项目的引用。
Yes. Both multiple projects and multiple namespaces make a lot of sense if you are building something non-trivial.
Your idea about having general functionality in one project, that you can reuse for other solutions, is a good one. It's all about code reuse and separation of concerns.
To use types from other projects in your Main Project, you should add a reference to the required projects using the Add Reference dialog.