What is the proper use of a C # namespace?

I come from the Java background, and I see that many people say namespaces = packages, but looking back at the available code, it doesn't seem to me that people use namespaces like the packages used.

I am currently working on a DLL to manage all of my database access for sharing between two Windows applications. So far I have created packages like I would like for Java, so I have domain names, services, DAOs (I call it Repositories) from my top level. It's right? Has anyone written best practice for namespaces? I suppose this is probably a very insignificant moment, but I do not want to go so as to speak against the grain.

+3
source share
4 answers

A little subjective, there is no "final, correct" answer to this question.

Here, as I do, with the intention of assembling assemblies between projects.

I have a company name FooBar (+1 for originality, anyone? :)

All your builds begin with this root namespace. We have many general meetings.

Things like:

  • HTML Helpers MVC (UI). They are included in one assembly.
  • Shared repository. A repository template implemented using generics for reuse.
  • LINQ Extension methods (paging, general syntactic sugar factory). Again, they go in one assembly.

So, our FooBar Namespace Universe might look like this:

FooBar
|
 ---- FooBar.Common.Mvc
|
 ---- FooBar.Common.DataAccess
|
 ---- FooBar.Common.Linq
|
 ---- FooBar.ProjectOne (ASP.NET MVC Web Application)
|     |
|      --- FooBar.ProjectOne.Repository (makes use of FooBar.Common.DataAccess)
|     |
|      --- FooBar.ProjectOne.WebMvc (makes use of FooBar.Common.Mvc)
|
 ---- FooBar.ProjectTwo (WPF Application)
      |
       --- FooBar.ProjectTwo.Repository (makes use of FooBar.Common.DataAccess)
      |
       --- FooBar.ProjectTwo.BindingServices (makes use of FooBar.Common.Linq)

Do you know what I mean?

, " ", .

, .

"- " ( ).

+10

, , MSDN.

, :

<Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]

:

FooCompany.BarProduct.Baz
+3

_. System.Module, . LogicStudio.ERP.GeneralLedger

0

Source: https://habr.com/ru/post/1769456/


All Articles