views:

214

answers:

2

Hello everyone,

How do you understand "No control over your namespaces" namespace issue, quoted from,

http://reddnet.net/code/asp-net-web-site-vs-web-application-project-part-2/

Here are more background:

one of the cons of web site project type of VSTS 2005 is, my confusion is what exactly means "no control over your namespace"?

•No control over your namespaces. Sure, you can manually add namespaces to pretty much anything, but visual studio will fight you every step of the way. With generated code such as ADO.NET DataSets and such, this gets very hard to control. Eventually you will give up and just let VS put everything in the default namespace. In large applications this gets very annoying, especially if you like a well structured application.

Appreciate if anyone could show a sample here.

thanks in advance, George

+1  A: 

Just test this: create a Web Application and a Web Site, then take a look to the namespaces created into the Default.aspx.cs:

  • WebSite: has no namespace
  • WebApplication: has namespace

When you have a very big application it's impossible to find your classes without namespaces.

Now create a DataSet:

  • WebSite: no .Designer.cs created -> namespace will be created automatically on the fly
  • WebApplication: .Desinger.cs created with proper namespace.
jmservera
@jmservera, 1. even if WebSite project type does not generate namespace, we could add the namespace manully by ourselves, is that fine? 2. "Now create a DataSet" -- not sure what do you mean create a DataSet. I always programmatically create DataSet by using new DataSet(...) in my code, what do you mean "create a DataSet" here? What is the impact if no .Designer.cs created?
George2
@George2, I meant: Right Click Web Site->Add new item...->DataSet, then you design a typified dataset definition into your project, that creates a class for it. If you do it into a WebSite you cannot set its namespace manually because each time you design it it will be overwritten.
jmservera
+1  A: 

George, Web Sites are not specific to VSTS. That's a normal Visual Studio feature, haunting us since Visual Studio 2005.

Also, see http://stackoverflow.com/questions/237664/web-site-vs-asp-net-web-application-in-visual-studio.

John Saunders
Yes, John. But this link does not answer my question. Any ideas or comments to my confusion mentioned in my original post?
George2
It means that in a project, you can set the root namespace for the project. Pages created in the root of the project will get that namespace. If you create subfolders, then pages created in them, will get the root namespace plus the name of the subfolder, all the way down. You therefore have control over the namespaces that VS will create when you add an item. "No control" does not mean you couldn't manually change the namespaces, though that will screw some things up, as parts of your site will expect no namespace, but you've now created one. Simple answer: don't use web sites.
John Saunders