![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I am making a first attempt at building a n-tier app and have it organised with the following projects: GUI.exe Business.dll DataAccess.dll GenericDA.dll data access references genericDA, business references the dataaccess, and GUI references business projects but my problem comes becuase of the way i want to seperate my classes, which i can best explain using an example: i have a table called user - which has a username and email address. my DataAccess.dll has a class called UserCRUD which reads and writes to the database,the get method of UserCRUD has a return type of User -this return type i want to define in the Business layer but i cant figure out how to connect the two layers - how do i make the dataaccess layer aware of the business layer? i tried adding a project reference to my business project but it says that is a circular reference. Can someone tell me what i am doing wrong? is it possible for me to reference a business layer defined object in my dataaccess layer? if not is there a better way to approach this? Many thanks Owen |
#3
| |||
| |||
|
|
Hi Owen, There are at least 3 things you could do: 1) Extract business objects (or data objects) such as User into a third assembly which you then reference from both > Business.dll and DataAccess.dll. In this scenario they will share the common type. If you want to have "active" objects eg.: User user = new User("username", email (AT) something (DOT) com"); user.Save(); then it's probably a bad solution but if the classes are only for carrying data then that may be the way to go. 2) Make UserCRUD Get methods return IDataReader and construct the object in the Business.dll (you can have the object construction logic in another assembly). Insert methods would then have to take multiple parameters (each property of your User object eg.: UserCRUD.Insert(string userName, string email) instead of accepting the actual instance of the User class). 3) Make the User class (Business.dll) inherit from UserData class (DataAccess.dll or better yet a separate assembly). Data access layer would then return an instance of UserData (only a data carrying object) class which could be transformed into a business object (User class). This would allow the business objects to call the data access layer and provide the above mentioned user.Save() functionality. You can also look around for ORM tools, see what kind of code those give you and use those ideas. Does that help? Best regards, Robert Wilczynski. Hi, I am making a first attempt at building a n-tier app and have it organised with the following projects: GUI.exe Business.dll DataAccess.dll GenericDA.dll data access references genericDA, business references the dataaccess, and GUI references business projects but my problem comes becuase of the way i want to seperate my classes, which i can best explain using an example: i have a table called user - which has a username and email address. my DataAccess.dll has a class called UserCRUD which reads and writes to the database,the get method of UserCRUD has a return type of User -this return type i want to define in the Business layer but i cant figure out how to connect the two layers - how do i make the dataaccess layer aware of the business layer? i tried adding a project reference to my business project but it says that is a circular reference. Can someone tell me what i am doing wrong? is it possible for me to reference a business layer defined object in my dataaccess layer? if not is there a better way to approach this? Many thanks Owen |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |