Namespace/solution structure

对着背影说爱祢 提交于 2019-12-01 15:47:22

There's a million ways to skin a cat. However, the simplest one is always the best. Which way is the simplest for you? Depends on your requirements. But there are some general rules of thumb I follow.

First, reduce the overall number of projects as much as possible. When you compile twenty times a day, that extra minute adds up.

If your app is designed for extensibility, consider splitting your assemblies along the lines of design vs. implementation. Place your interfaces and base classes in a public assembly. Create an assembly for your company's implementations of these classes.

For large applications, keep your UI logic and business logic separate.

SIMPLIFY your solution. If it looks too complex, it probably is. Combine, reduce.

My advice, having embarked on a similar undertaking, is to not agonize over the name spaces..

Just start developing with a few important loose guidelines, because however you start out, your project is organic, and you will end up reorganizing the name spaces and classes over time.

Don't waste time talking too much about your project. Just do it.

I recently experienced the exact same at work. Lots of ad-hoc code that needed to be structured and organised.

Its real hard at first, since there is so much. I think the best advice I could give is to just invest time in it on the wind down on a Friday afternoon, for a couple of weeks I would just pick an app/chunk of code, examine what was there, think about what we could make generic, copy it, put it into the new library wherever I thought it should be. Once I had all the code within an application migrated, I would then work on refactoring the application to work from the common framework.. This sometimes caused problems that needed to be fixed, but so long as your thorough it shouldn't be too big a deal.

Piece by piece, thats the only way to do it.

In terms of structure, I tried to kind of mimic the MS namespacing since for the most part its pretty logical (e.g. Company.Data , Company.Web , Company.Web.UI and so on.

One of the major benefits is probably the amount of code dupe removed. Yeah a little refactoring was required in the apps, but the code base is a lot leaner, and in many ways "smarter".

Another thing I noticed is that I would often have problems trying to figure out where to put stuff (in terms of namespacing) since I wasn't sure what it belonged to. Now this really concerned me, I viewed it as such a bad smell. Since the re-org everything now falls in to space much more nicely. And with the (now very small amount) of application specfic code, they get put into Company.Applications.ApplicationName This helps me really think about business objects a lot more since I dont want too much within this namespace, so I come up with more flexible designs.

Sorry for the long post.. It's kind of rambling!

We name the assemblies in .NET the following way Company.Project.XXXX.YYYY where XXXX is Project and YYYYY is subproject, for example:

  • LCP.AdmCom.Common
  • LCP.AdmCom.BusinessObjects
  • LCP.AdmCom.Common.Dal

We take this from a book call Framework Design Guidelines by Krzysztof Cwalina (Author), Brad Abrams (Author)

For large projects the approach I like to take is to have one Domain namespace for my business objects and then use Data Transfer Objects (DTO's) in my layers where storage and retrieval of the business object is needed. A DTO is a simple object that doesn't contain any business logic.

Here is a link that explains a DTO:

http://martinfowler.com/eaaCatalog/dataTransferObject.html

Large solutions with lots of projects can be quite slow to compile, but are easier to manage together.

I often have Unit test assemblies in the same solution as the ones they're testing, as you tend to make changes to them together.

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