Separate projects or multiple class files … namespace best practice in C#

后端 未结 5 1103
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 03:32

I\'m creating a library for use with an application that I am building. I am building a name space structure similar to below.

MyNamespace.Validation
MyName         


        
5条回答
  •  盖世英雄少女心
    2021-01-13 04:10

    There are pros and cons to both approaches, which you need to personally decide between for your own circumstance.

    Pro to multiple projects:

    • Separate assemblies allow the compiler to provide more strict guidance, potentially preventing coupling from creeping through. This allows you to maintain the dependencies better.
    • Separate assemblies can be loaded as needed in other projects, potentially easing reuse.
    • Separate assemblies can prevent unnecessary code from being loaded into a process, since they're loaded on demand.

    Cons to multiple projects:

    • More complex deployment, as more files need deployment (minor)
    • Slower build/compile, and even potentially load times from loading multiple assemblies (minor)

    Personally, I think the pros far outweigh the cons in most cases. I typically will split my namespaces into separate assemblies, provided they are not related. In your case, you're working on 4 very different concepts, so my gut feeling is that splitting makes the most sense.

提交回复
热议问题