Namespace problem with basic User, Data, Logic architecture

来源:http://www.imcoder.org/architecture/186756.htm

 

Q:

Hi everyone,

This is my first major asp.net project, and it's an Intranet application for a retail company. The basic architecture I am using has three namespaces:

  • User: All code for UI elements like custom controls, etc.
  • Logic: Business logic where objects like Customer, Order, ShoppingCart, Employee and so forth exist.
  • Data: All DB access occurs here.

The idea is that the user layer only accesses the logic layer, and the logic layer only accesses the data layer to keep everything modular and extendable in the future. The whole project itself has the namespace Intranet, so then the available namespaces are Intranet.Logic, Intranet.Data, and Intranet.User.

 The Problem:

I have a file in the data layer like so:

Imports Intranet.Logic

Namespace Data
Public Class Shipping

Public Shared Function loadUPSMethods(ByVal orderObj As Order) As List(Of ShippingMethod)
'<some code>
End Function

End Class
End Namespace
I also have a file in the logic layer like so:
Imports Intranet.Data

Namespace Logic
Public Class Order

Public Function GetShippingMethods() As List(Of ShippingMethod)
'<some code>
list = Shipping.loadUPSMethods(Me)
'<some code>
End Function

End Class
End Namespace




When I try to run the code, I get the following compile error:

Compiler Error Message: BC30311: Value of type 'Logic.Order' cannot be converted to 'Intranet.Logic.Order'.
at this line:

             list = Shipping.loadUPSMethods(Me)
 
This doesn't make any sense to me, since Intranet.Logic.Order and Logic.Order are the same thing. I have tried using fully justified paths, but that hasn't solved anything. I use this structure in lots of different files all over the place, and it works just fine. This one has really got me stumped. Any suggestions?
A:

Are your layers split into different assemblies? As a test try amending this line:

Namespace Intranet.Logic
Public Class Order

Public Function GetShippingMethods() As List(Of ShippingMethod)
'<some code>
list = Shipping.loadUPSMethods(Me)
'<some code>
End Function

End Class
End Namespace


A:

I have already tried that, but it didn't work. .Net seems to assume the "Intranet." automatically.

When I use "Intranet.Logic" then GetType() on the Order object returns "Intranet.Intranet.Logic"

As to assemblies; I'm somewhat new to .Net, so I am not 100% sure what assemblies are. If they are what I think they are (separate DLL files that you reference), then no, all of this project is in one assembly.

A:


Visual Basic automatically wraps your code in a default namespace, maybe this is your problem. To remove the default namespace right click on your project select properties then on application tab.


Thats what I was getting at yes.

A:

 This may help http://bytes.com/forum/thread266745.html

"Also, VB.NET provides a default namespace for the project and this
becomes prepended to the namespace to form the CLR namespace.

So, if you have a project with default namespace "Blinex.Charts" and
then a class:

Namespace Assets
Class LimitLine
End Class
End Namespace

Then the namespace in the CLR for referring to that class is
Blinex.Charts.Assets.LimitLine.

So in VB.NET even when you have no Namespace statement, classes are
still in a namespace defined by the project."

A:

 Yup. I assumed that what you described above is what's happening based on what I observed.

I'm quite happy to let VB.Net wrap the defualt namespace around my code - that makes sense and it's what I want.  What I don't understand is what the problem is. Why can an item of type Logic.Order not be converted to the type Intranet.Logic.Order, since those two types are one and the same! It makes no sense!

 This is a pretty frustrating issue I am having, and I can't seem to find any other references to it online. Surely I'm not the only one who has ever had this issue... 

A:

Form your what you say in your earlier post:

It appears that your Order object is within the namespace Intranet.Intranet.Logic, have you named your project 'Intranet'?

You could try and add the Global keyword as below:

Imports Intranet.Logic

Namespace Data
    Public Class Shipping

        Public Shared Function loadUPSMethods(ByVal orderObj As Global.Intranet.Intranet.Logic.Order) As List(Of ShippingMethod)
            '<some code>
        End Function

    End Class
End Namespace

posted @ 2008-08-15 11:18  KK in cnblog  阅读(223)  评论(0编辑  收藏  举报