Implementing a namespace over more than one assembly?

T

thechaosengine

Hi all,

Can anyone tell me if it is advisable (or even possible) to define a namespace
across 2 or more assemblies?

For example, consider the namespace SampleApplication.Data.Providers

Would it be possible to have assembly A define a class as part of that namespace
as well as Assembly B also declaring a class to be within it as well?

In particular, I have a number of data providers. It would be useful (I think)
to declare them in the same namespace, but for the purposes of a demonstration
I'm doing, each provider must exisit in its own seperately deployed assembly.

Is this possible and is it a good idea?

Thanks to anyone who can share some advice! :)

Kindest Regards

tce
 
A

Arthur Dent

Actually you can see this very thing in action in some of MSs own
assemblies...

System.Data namespace which is (i believe) defined in mscorlib.dll.
System.Data.OracleClient which is defined in the
System.Data.OracleClient.dll

I dont know how name resolution would work though if you had two classes
named the same
from two different assemblies in the same namespace both in reference in one
project.

I did something VERY similar to your project... what i did, is i made myself
one root assembly which
had my base classes defined, from which the individual providers all
inherited (significant shared code).

I put that in dll My.Data.dll (for example)
Then i put the base classes in their in the namespace My.Data.Definitions

Then each provider can be written in its own assembly such as :

My.Data.Oracle.dll where NS = My.Data.Oracle
My.Data.SqlServer.dll where NS = My.Data.SqlServer
My.Data.ODBC.dll where NS = My.Data.ODBC and so on.

Then you ref in your project the base dll My.Data.dll, and the appropriate
one for whichever provider you need.

HTH.
 
M

Mythran

Arthur Dent said:
Actually you can see this very thing in action in some of MSs own
assemblies...

System.Data namespace which is (i believe) defined in mscorlib.dll.
System.Data.OracleClient which is defined in the
System.Data.OracleClient.dll

I dont know how name resolution would work though if you had two classes
named the same
from two different assemblies in the same namespace both in reference in
one

To add additional assemblies that do this:

mscorlib.dll - Defines most of the System root namespace's classes.
System.dll - Defines only a few of the System root namespace's classes.

HTH :)

Mythran
 
T

thechaosengine

Gentlemen, thank you kindly for your advice. You have both been a great help.

Thanks again

Kindest Regards

tce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top