How to build a Business Object using CSLA.NET to access data from 2 different Databases.

How to build a Business Object using CSLA.NET to access data from 2 different Databases.

Old forum URL: forums.lhotka.net/forums/t/4620.aspx


tarekahf posted on Saturday, April 05, 2008

Requirement:

The Data required is split among 2 different Database Engines, say, Adabas on UNIX and SQL Server on Windows 2003 Server.

We are using CONNX 10.5 to have ODBC or OLEDB Access to the Adabas Database Tables, and it works successfully.

On the UI, sometimes we need to access the data only from Adabas, and some other times, from both, Adabas and SQL Server, for example, to get a list of Staff Info in one list to be attached to the GridView DataSource.

In the normal situation, the data is supposed to be stored in one Database say only from Adabas. So, the SQL String looks like the following:

"select StaffID, StaffName, StaffAge, Salary from AdabasTable;"
(Note: This is a simplistic example, of course, the actual case is more complicated).

But the above cannot be done because the "Salary" is stored in different Database, in SQL Server, which requires another connection string, and he SQL String for accessing the data from Adabas say:

"select StaffID, StaffName, StaffAge from AdabasTable"

...and the SQL String for access the data from SQL Server say:

"select staffid, Salary from SQLServerTable"

Of course, StaffID is the primary key and same in both tables.

Each SQL String must be executed against the appropriate Connection String, which is stored in the web.config file. So, we have 2 different Connection Strings.

How I can design a Business Object (class) that can retrieve the list of staff, from Adabas only, then another class which is reusing the first one to retrieve the same list which has both data from Adabas and SQL Server, and combine the result in one list ?

One way to solve this problem, is to define a Linked Server in SQL Server, use OpenQuery() function to open the Adabas Table in SQL Server, and use one SQL String to join the tables between Adabas and SQL Server. As a mater of fact, this is what I am doing right now, but this method defeats the concepts of OOP, as you may have already built a class to retrieve the first part, and all what you need to do is to get second part of the data from the other Database Table. The ideal way is to define another class and re-use the functionality of the first class (bu inheritance), but I cannot figure out how to do that exactly.

Say the class/methods look something like the following:

(Note: The syntax my not be 100% correct, this is just for clarification purposes)

public class clsStaff1
private _StaffID as String
private _StaffName as String
private _StaffAge as Integer
private Salary as double
public propert ReadOnly StaffID() as String
  get
    return _StaffID
  end get
end property
...bla bla bla ...
... bla bla...
... same for StaffName, StaffAge, and Salaray ... read only is needed...
... bla bla...
public shared function getStaffList() as DataTable
  con = open connection to Adabas Table
  SQLStr = "select StaffID, StaffName, StaffAge from AdabasTable"
  Execute the SQL String and return the DataTable using Adaptor for example !
  return the resultant DataTable (for use with the DataSourceContorl/GridView for example)
end function
end class

The question is: How to define another class "clsStaff2" the re-uses the first class "clsStaff1" (by inheritance) and just add the the "Salary" from SQL Server Table ?

I think one way to do that is to do the Join between the 2 DataTables in the VB Code, is this possible ?

Is this approach practical in the first place ?

I hope I was able to clarify my requirement and appreciate your help.

Tarek.

david.wendelken replied on Saturday, April 05, 2008

Don't confuse the fact that you have two database vendors with business object design.

The first is an unfortunate situation, the second an opportunity.

Design your business objects the way they should be.
I would not define two business objects just because I had two databases. 

Inside your data access methods in your business objects, you have several options:

  1. open database one and get that data.  open database two and get that data.  merge into the appropriate business object data structures.  from the outside world's point of view, there is only one business object.  Ditto on insert/update/deletes.   The sample business objects are pretty clear on where the selects, inserts, updates, etc. go.
  2. make the database-to-database links you described.  open one database and issue the queries from both.  again, from the outside world's point of view, there is only one database object.

tarekahf replied on Saturday, April 05, 2008

Thanks a lot ... I agree with you 100% ...!

david.wendelken:

Inside your data access methods in your business objects, you have several options:

  1. open database one and get that data.  open database two and get that data.  merge into the appropriate business object data structures.  from the outside world's point of view, there is only one business object.  Ditto on insert/update/deletes.   The sample business objects are pretty clear on where the selects, inserts, updates, etc. go.

Should I do the merger one record at a time ? Remeber that the requirement is to return a LIST of records which has data fields from 2 different Databases ... I am just wondering how would that be possible in VB Code ? Meaning:

Open First Connection / SQL

Open Second Connection / SQL

Loop over first SQL String

  Get Next Record from first SQL

  Get Field Data from first SQL 

  Lookup the Second SQL against the StaffID

  Get Field Data from the Second SQL

  How to merge the fields here, in ArrayList? , DataTable ? Is it good approach ?

End Loop until end of file of first SQL.

Return the Merged Data in one list.

make the database-to-database links you described.  open one database and issue the queries from both.  again, from the outside world's point of view, there is only one database object.

Yes, this is the method I am following now, and it is working successfully. But the only problem is that, sometimes, you already developed the Business Object that represents the First Part. After some time, you need additional parts, so you Create the Database and I was thinking now, how I can re-use the First Business Object ? This is my problem.

Regards ...

Tarek.

JoeFallon1 replied on Saturday, April 05, 2008

I would probably get 2 lists (with 1 SQL statement each) and close all connections.

Then in code you can figure out how to merge them based on the same PK value. Use loops here - not while executing SQL commands.

Joe

 

tarekahf replied on Thursday, April 10, 2008


(NOTE: I am not receiving notification with each reply. I could not find an option to enable notification with each replyonly to my post in these forums. Please help.)

JoeFallon1:

I would probably get 2 lists (with 1 SQL statement each) and close all connections.

Then in code you can figure out how to merge them based on the same PK value. Use loops here - not while executing SQL commands.

Joe



I though that it would e better to follow OO recommendations for code reusability.

I mean, since that I already developed the first BO to fetch the list of Staff Info, then I would develop another BO that inhirits the first one, prepare and execute the other SQL Statement to get the second list (from the other Database), and then merge the 2 lists togther using code and depending on the PK. Finally, return the merged list as the result.

My question here, would be is: what Object Type you will use for the list ?

- Array list of objects,

- Data Table

- Data Set

...etc ?

I have not used CSLA.NET yet... I am still doing some reading and playing with the PT Sample application. But I could not figure out how it is done there?

I am interested to know how you would implement such requirement in CSLA.NET ?

Currently, I am using Array List of Objects to return the list to the Datasource Control in the UI side. This methd works fine with me as of now.

In general, I think this is a common issue not only related to such specific case I mentioned in this thread ? So what do you do ?

Do you execute the SQL Statement, and return the result AS IS (using say Data Adaptor Fill method to populate a Data Table), or do you have to loop through the result (using say command ExecuteReader method)  to do some processing for each record from the Data Reader before adding the record to the result list ?

In CSLA.NET, in case you need to write a Business Object that will return a List of Data (say Staff Info), then you many have to wirte a loop that will read each and every record, one at a time, do some processing, calculation, validation, authorization, and based on the final resutl, add the required record and/or data fields to the resultant list... correct ?

Although you can do some of the processing in Stored Procedures, or even on the Query Select Statement (say concat First+Middle+Last Name to get Staff Name, and Convert it to Proper Case) , but in think it is more appropriate to keep such processing inside the code, and in some cases, you may prefer to do it inside the Query.

Any feedback will be appreciated.

Tarek.

david.wendelken replied on Thursday, April 10, 2008

Good oo design is based upon what the Business definition of the object should be.

 

Whether that object’s comes from 0, 1 or 5 tables is irrelevant.

 


From: tarekahf [mailto:cslanet@lhotka.net]
Sent: Thursday, April 10, 2008 7:45 PM
To: david_wendelken@nc.rr.com
Subject: Re: [CSLA .NET] How to build a Business Object using CSLA.NET to access data from 2 different Databases.

 


(NOTE: I am not receiving notification with each reply. I could not find an option to enable notification with each replyonly to my post in these forums. Please help.)

JoeFallon1:

I would probably get 2 lists (with 1 SQL statement each) and close all connections.

Then in code you can figure out how to merge them based on the same PK value. Use loops here - not while executing SQL commands.

Joe



I though that it would e better to follow OO recommendations for code reusability.

I mean, since that I already developed the first BO to fetch the list of Staff Info, then I would develop another BO that inhirits the first one, prepare and execute the other SQL Statement to get the second list (from the other Database), and then merge the 2 lists togther using code and depending on the PK. Finally, return the merged list as the result.

My question here, would be is: what Object Type you will use for the list ?

- Array list of objects,

- Data Table

- Data Set

...etc ?

I have not used CSLA.NET yet... I am still doing some reading and playing with the PT Sample application. But I could not figure out how it is done there?

I am interested to know how you would implement such requirement in CSLA.NET ?

Currently, I am using Array List of Objects to return the list to the Datasource Control in the UI side. This methd works fine with me as of now.

In general, I think this is a common issue not only related to such specific case I mentioned in this thread ? So what do you do ?

Do you execute the SQL Statement, and return the result AS IS (using say Data Adaptor Fill method to populate a Data Table), or do you have to loop through the result (using say command ExecuteReader method)  to do some processing for each record from the Data Reader before adding the record to the result list ?

In CSLA.NET, in case you need to write a Business Object that will return a List of Data (say Staff Info), then you many have to wirte a loop that will read each and every record, one at a time, do some processing, calculation, validation, authorization, and based on the final resutl, add the required record and/or data fields to the resultant list... correct ?

Although you can do some of the processing in Stored Procedures, or even on the Query Select Statement (say concat First+Middle+Last Name to get Staff Name, and Convert it to Proper Case) , but in think it is more appropriate to keep such processing inside the code, and in some cases, you may prefer to do it inside the Query.

Any feedback will be appreciated.

Tarek.


tarekahf replied on Saturday, April 12, 2008

I did some research on this issue and found this useful link:

http://msdn2.microsoft.com/en-us/library/8bw9ksd6(VS.80).aspx


I can use Typed or Untyped Datasets, Data Tables and perform merging with the help of DataRelation Object.

As per my initial understanding of CSLA framework, CSLA uses untyped Data Sets and uses Data Adapters to populate Data Sets, and binds the result to the UI Controls.

Instead of using Fill method of the Data Adapter, I can populate the Data Set/Data Table record by record and perform the required merging/join, calculation, processing before adding the result to the Data Row Collection of the Data Table.

I hope that my understanding is correct, if yes, do you think this is a good approach ? Any other suggestions ?

Tarek.

RockfordLhotka replied on Saturday, April 12, 2008

CSLA doesn't do the data access for you at all. So it doesn't use DataSets or TableAdapters.

But you can use DataSets and TableAdapters to write your data access code if you want to. Or you can use raw ADO.NET connection/command/datareader objects (they are faster, but may require more coding).

Either way, you will need to write code to talk to each database and get the results. Then you copy the resulting values into the fields of your CSLA business object. Then you use data binding to bind the business object to the UI controls.

tarekahf replied on Sunday, April 13, 2008

RockfordLhotka:

CSLA doesn't do the data access for you at all. So it doesn't use DataSets or TableAdapters.

But you can use DataSets and TableAdapters to write your data access code if you want to. Or you can use raw ADO.NET connection/command/datareader objects (they are faster, but may require more coding).

Either way, you will need to write code to talk to each database and get the results. Then you copy the resulting values into the fields of your CSLA business object. Then you use data binding to bind the business object to the UI controls.

Rocky, thanks a lot !

Please allow me to clarify some points which are not clear to me.

For the time being, I am interested in finding out what is the Data Type used to return a list of objects to be bound on say a GridView, and how this is done ?

Ref. to PTracker Sample Application (PTWeb), I checked the code for "ProjectList" class and found the following:

<Serializable()> _
Public Class ProjectList
Inherits ReadOnlyListBase(Of ProjectList, ProjectInfo)
Public Shared Function GetProjectList() As ProjectList
  Return DataPortal.Fetch(Of ProjectList)(New Criteria)
End Function
...
...
Private Sub Fetch(ByVal nameFilter As String)
  RaiseListChangedEvents =
False
  Using cn As New SqlConnection(Database.PTrackerConnection)
  cn.Open()
  Using cm As SqlCommand = cn.CreateCommand 
  With cm
  .CommandType = CommandType.StoredProcedure
...
...
...
...
End Sub

I understand that this might be out of the scope of this forum, but we have already submitted a request to purchase 3 books about CSLA (from your website) and it might take some time to arrive. Also, it will take some time to read and understand. The code above is using some kind of advanced ASP.NET Concepts which I am not familiar with.

The management requested from our team members to do a research to select a Framework for developing .NET Applications (Windows and Web) to help streamline, standardized and reduce the development efforts. I must prepare a demo/presentation with a Sample Project as per our applications, and of course I must explain such concepts and be ready for questions.

I appreciate your help and understanding. I have the following questions:

1. In a High-Level Language , what is the code above doing ? I am very much confused with this notation: ... Inherits ReadOnlyBase (Of ProjectList, ProjectInfo...) .

2. Usually, DataSources for Lists are returnd as DataTables, DataSets or DataReader Objects, or even as ArrayList (which I usually use). How does this compare with the List returned by the "ProjectList" class ?

3. We usually use "Integrated Windows Authentication" to authenticate users, but this project is using Forms Authenticaiton. Do you have a sample project with Windows Authentication. For Roles and Authorization, I am very happy with the way it is implemented in the PTracker Application. Any advise how to quickly convert this application to use Windows Interated Authentication.

4. Do you have any adivse or recommendation or some material I can use for my presentation/demonistration about CSLA.NET.

(Note: We are evaluating CSLA.NET, NHibernate, DNN, WCSF, DataObjects.NET, Genome)

Tarek.

tarekahf replied on Sunday, April 13, 2008

One thing will be of a great help to me, if there is some effort spent before to implement the Application of the sample Northwind DB using CSLA.NET, with a some documentation.

I am sorry if I am asking for too much.

Tarek.

david.wendelken replied on Sunday, April 13, 2008

From a “sample application” point of view, you wouldn’t learn anything more from looking at a sample application based on Northwind instead of ProjectTracker.

 

There would just be more pages to look at.  The coding techniques would be the same.

 


From: tarekahf [mailto:cslanet@lhotka.net]
Sent: Sunday, April 13, 2008 4:19 AM
To: david_wendelken@nc.rr.com
Subject: Re: [CSLA .NET] RE: How to build a Business Object using CSLA.NET to access data from 2 different Databases.

 

One thing will be of a great help to me, if there is some effort spent before to implement the Application of the sample Northwind DB using CSLA.NET, with a some documentation.

I am sorry if I am asking for too much.

Tarek.



david.wendelken replied on Sunday, April 13, 2008

tarekahf:

For the time being, I am interested in finding out what is the Data Type used to return a list of objects to be bound on say a GridView, and how this is done ?

You are returning a strongly typed collection that will only hold ProjectInfo objects.

tarekahf:

I understand that this might be out of the scope of this forum, but we have already submitted a request to purchase 3 books about CSLA (from your website) and it might take some time to arrive. Also, it will take some time to read and understand. The code above is using some kind of advanced ASP.NET Concepts which I am not familiar with.

Neither was I when I started working with CSLA! :)

I'm not sure what part of the world you are in and what the salary structure is there.  I'm working in Africa right now and a good technical book is a BIG chunk of a local programmer's monthly salary.  If where you are working has a similar wage structure, I understand waiting.  But, if you are working for North American/Western European wages, get off your duff and order a copy of the books for yourself.  Consider it an investment in yourself.  If you master the material in the CSLA framework, you can qualify for a job anywhere in the world, and they'll be darn glad to have you! :)  Even if you never use CSLA, the concepts that Rocky explains in his books will serve you very well.

tarekahf:

The management requested from our team members to do a research to select a Framework for developing .NET Applications (Windows and Web) to help streamline, standardized and reduce the development efforts. I must prepare a demo/presentation with a Sample Project as per our applications, and of course I must explain such concepts and be ready for questions.

I am pretty familiar with DNN.  It's a nice product. 

If I needed a free portal product, I would very much consider it.   For building in house applications, I prefer CSLA.   I have't used the other frameworks, so no comment there.

tarekahf:

1. In a High-Level Language , what is the code above doing ? I am very much confused with this notation: ... Inherits ReadOnlyBase (Of ProjectList, ProjectInfo...) .

As for "inheriting" code, that is making use of a .Net concept called Generics.  Have you ever written a method that accepted integer arguments, then needed to write the same basic code to handle floating points and strings?  That's what generics are for.  You write some standardized code and put some "compiler placeholders" in it.  When you inherit from a generic class, you have to tell it what object types are to be substituted for the compiler placeholders.  The compiler does a quick find and replace operation and builds a custom class tied to the object types you provided.  There are lots of web articles on how to use generics.  (I'm on a very slow network connection, it took 5 minutes just to wait on the reply button, so you'll have to look for one yourself.)

tarekahf:

2. Usually, DataSources for Lists are returnd as DataTables, DataSets or DataReader Objects, or even as ArrayList (which I usually use). How does this compare with the List returned by the "ProjectList" class ?

A strongly typed collection is a better basis for business objects.   I think they are much easier to use than the built-in objects.

tarekahf:

3. We usually use "Integrated Windows Authentication" to authenticate users, but this project is using Forms Authenticaiton. Do you have a sample project with Windows Authentication. For Roles and Authorization, I am very happy with the way it is implemented in the PTracker Application. Any advise how to quickly convert this application to use Windows Interated Authentication.

There are several threads covering Windows Authentication and CSLA.  It works great with Windows Authentication.  The sample project doesn't include it because it is a sample product, and has to work for people who aren't using Windows Authentication.   The CSLA business objects integrate VERY WELL with this technology.

tarekahf:

4. Do you have any adivse or recommendation or some material I can use for my presentation/demonistration about CSLA.NET.

Send me a private email and I'll email you a powerpoint presentation covering csla basics.  It's meant to work with the sample Project Tracker application.

Or maybe Rocky can post it on his website and save me getting a bunch of emails? :)

CSLA makes very good use of inheritance, interfaces, and generics.   If you aren't well versed in those topics, you will want to study up.  You will be glad you did!

tarekahf replied on Sunday, April 13, 2008

Dear david.wendelken,

Just a quick note about the books. I checked a while ago, and I was told that they have been ordered (3 books). It is not a problem of cost or salary (as the books are very affordable). It is a problem of availability. I can order them on-line, but I why do I have to bather, if the management is very keen to provide us all the books we need ?! As of now, I have more than 6 books on ASP.NET, so this is not a problem.

Actually, even if I have the CSLA.NET books today, I still need at least a week to update my knowledge, and the time limit that was given to me is not enough (in addition to the other assignments I have). One of my colleagues have already submitted a very nice proposal for the COMPLETE requirements using DNN and Codesmith, and he provided a complete step-by-step document showing how to build a Sample Northwind Application using such approach. If I do not give something similar to describe the concept, there will be little chance to have CSLA.NET Adopted.

Tarek.

RockfordLhotka replied on Sunday, April 13, 2008

tarekahf:

I understand that this might be out of the scope of this forum, but we have already submitted a request to purchase 3 books about CSLA (from your website) and it might take some time to arrive. Also, it will take some time to read and understand. The code above is using some kind of advanced ASP.NET Concepts which I am not familiar with.

There are three books. The Expert 2005 Business Objects book is paper and must be ordered through a regular bookstore or online book store. It would take time to arrive.

The two ebooks on http://store.lhotka.net are ebooks, PDF, and so need to be downloaded directly from the store web site once the purchase is complete. They take no time to arrive, so if you don't have them then you should return to the web site and download them.

tarekahf:

1. In a High-Level Language , what is the code above doing ? I am very much confused with this notation: ... Inherits ReadOnlyBase (Of ProjectList, ProjectInfo...) .

CSLA .NET provides a set of base classes, like ReadOnlyBase, which provide features that are useful when building an object-oriented business layer. The key is that CSLA helps build an object-oriented business layer, and so if you are looking for something more like a DataSet model then CSLA may be a bad fit.

CSLA helps you build a business layer composed of objects, where the objects encapsulate validation, authorization, implement data binding, n-level undo and several other very useful features. It provides a standard approach you can use to implement these behaviors, and helps you reduce code and complexity within this environment.

ReadOnlyBase is a base class that is used to create read-only objects. BusinessBase is a similar base class that is used to create editable objects.

tarekahf:

2. Usually, DataSources for Lists are returnd as DataTables, DataSets or DataReader Objects, or even as ArrayList (which I usually use). How does this compare with the List returned by the "ProjectList" class ?

If you create an object-oriented business layer then your UI should only interact with business objects. Never with data access technologies like the DataSet or ADO.NET. ProjectList inherits from ReadOnlyListBase, which provides support for read-only lists of read-only objects, including rich support for data binding (WPF, Windows Forms and Web Forms), authorization and abstract data access.

tarekahf:

3. We usually use "Integrated Windows Authentication" to authenticate users, but this project is using Forms Authenticaiton. Do you have a sample project with Windows Authentication. For Roles and Authorization, I am very happy with the way it is implemented in the PTracker Application. Any advise how to quickly convert this application to use Windows Interated Authentication.

Yes, the PTWeb application in ProjectTracker uses forms authentication. And Chapter 10 in the Expert 2005 Business Objects book also discusses the use of the MembershipProvider (and people have discussed it on this forum too) if you want to use that feature of ASP.NET.

tarekahf:

4. Do you have any adivse or recommendation or some material I can use for my presentation/demonistration about CSLA.NET.

The primary sources of information about CSLA .NET are the three books, www.lhotka.net/cslanet and this forum.

tarekahf replied on Sunday, April 13, 2008

Many thanks to Rocky and David for the valuable replies. I am in a much better position now.

I have create a new project from scratch to develop a sample application based on CSLA.NET which is relevant to our environment. Initially, I will focus on bulding the Web Presentation, UI, and Business Logic. It will be about Country List and Staff Info (the BOs), and the relationship between both entities. I will try to connect such BOs to 2 different Databases (Adabas on UNIX accessed via CONNX Gateway, and SQL Server). I am copying the relevant bits and parts from the PTracker Application to the new application, and will try to enable Windows Authentication. I have found several threads and one article discussing this topic, and I have created a special thread for this subject, and received several replies.

I inquired about the eBooks we ordered (for CSLA 2.x and 3.x), and I was told that they are waiting for some confirmation number from PayPal or something like that for several days, it is taking longer than expected !!!. The other book (Business Objects for CSLA.NET 2.x) has been order from Amazon.com today (regular book).

Tarek.

RockfordLhotka replied on Sunday, April 13, 2008

If you or your purchasing agent is having trouble with the ebooks, they should email admin at Lhotka.net for help.

 

Rocky

 

tarekahf replied on Monday, April 14, 2008

RockfordLhotka:

If you or your purchasing agent is having trouble with the ebooks, they should email admin at Lhotka.net for help.

Rocky

Yes, it seems that there is a problem. I asked the person in charge to send email to the address you gave me.

In the mean time, could you please tell me if there is a way to purchase such books as Normal Books (not eBooks) from some other webstore ?

It seems that not all Books of CSLA are available in Amazon webstore.

The order of the book "Expert VB Business Objects" is submitted from Amazon.com and expexted to arrive soon.

Tarek.

RockfordLhotka replied on Monday, April 14, 2008

The ebooks are available in PDF form only, and only from http://store.lhotka.net.

 

Rocky

 

tarekahf replied on Monday, April 14, 2008

Ok, will take care of the books.

I have started making some effort on Windows Authenticaiton with CSLA.

If you have some time, please check the details here:

http://forums.lhotka.net/forums/22785/ShowThread.aspx#22785

I appreciate your comments.

Tarek.

tarekahf replied on Tuesday, April 15, 2008

I managed to implement Mixed Authentication successfully in addition to developing a simple new BO. Check details here:

http://forums.lhotka.net/forums/22855/ShowThread.aspx#22855

I appreciate your comments if there is something wrong in my approach.

I have the following very important questions, and appreciate your reply:

1. In the PTracker Sample Application, and in the new Sample Application I developed, I had some doubt about how to set a reference to CSLA DLLs. In the instructions for installing the application, it was mentioned to deploy the DLL to the GAC. But, I did not do that, because I do not know how, so I just simply set a reference to CSLA DLLs by Browsing to the csla.dll file from the csla project bin folder, after building it. Is this correct ? Is it absolutely necessary to deploy csla dll to CAG and use Strong Key or something like that ?

- When I set a reference to the csla dll from the Web Project, several DLLs showed in the references for different languages. But, in the Library Project, after setting the reference to csla dll, only one reference appeared ? Can you  please explain this ?

2. Suppose I have several applications using CSLA Framework. Each application is developed locally on a separate PC, and eventually they must be deployed to one Server Machine. What is the best way to reference the DLL ? All must reference the same file, or they must have a separate copy of the file in the BIN folder ? Will be there any problems for threading conflicts ? My colleague told me that referencing the different copies of the DLL will cause some kind of threading conflict (same code being executed in 2 copies of the same DLL) which will cause problem in updates. How does this apply to CSLA ? (I am sorry if I did not use the correct terms here, and I hope the point is clear)

3. Over time, we will be developing several Reusable Objects in Library Projects like that of the PTracker, which will be eventually a DLL File, right ? And as they are growing, we then have to group related BOs in separate DLLs to make it easier to manage and track. When there are so many DLLs and different versions for each, I think it cause something called DLL Hell !! Since there will be different versions of each DLL, complex project dependencies, and there will be a possibility that some projects will break due to deploying a new DLL version, which may require a recompile of the affected projects. I know this has nothing to do with CSLA, but I appreciate your input on how to avoid such problems.

4. In general, is it correct to say that we must use Web Services to expose the BO functionality to the consumers of the web services, and that we must avoid using direct reference to DLLs to avoid the threading problems and version contorl issue ?

I am not very much comfortable with the idea of Using Web Services instead of DLL References. I think we should use Web Services only when there is a real value for such approach.

Your feedback will be greatly appreciated.

Regards ...

Tarek.

tarekahf replied on Monday, April 21, 2008

Ok, I will try to be more focused now. I am preparing for a presentation tomorrow about CSLA.NET and appreciate your help.

I have already developed several Business Objects, for proof of concept, in DLLs using CSLA.NET Framework and used them in several other applications, and enabled both Integrated Windows Authentication and Forms Authentication.

I have some doubt about the multi-threading issue and the relationship with Web Services, DLLs and CSLA.NET. 

I have the following questions in that regards:

1. By default, when you develop a Web Service, are they Thread Safe ? Or do you still have to worry about Multi-threading problems due to the nature of the web server allowing requests to run in parallel in different threads ? So that, also, when writing a Web Service, you need to worry about Multi-Threading Issue ?

2. With regards to Developing Business Objects in DLLs and deploying them to a Web Server for use by other applications with direct reference, when do you have to worry about making the DLL Thread Safe ? Is it necessary to write your DLLs to be Thread Safe ? Do you have always to reference to Thread Safe DLLs in your web applications ?

3. Is CSLA.NET DLL Thread Safe ?

Tarek.

RockfordLhotka replied on Monday, April 21, 2008

tarekahf:

1. By default, when you develop a Web Service, are they Thread Safe ? Or do you still have to worry about Multi-threading problems due to the nature of the web server allowing requests to run in parallel in different threads ? So that, also, when writing a Web Service, you need to worry about Multi-Threading Issue ?

Generally yes. By the time your service code is running, ASP.NET has assigned you a thread for the duration of that service invocation and you'll remain on that thread unless you explicitly do something to create your own threads (or use the thread pool) - but that's no different than in any .NET code, and you'd know it if you created a thread.

Obviously many service requests may be running at the same time, but each one is on its own thread.

The only places you can get into trouble here is when using object instances that are shared across the AppDomain, because those objects could be used by multiple threads at once. And when calling static/Shared methods because those are global to the AppDomain.

Unless you go out of your way to do this, no object instances are typically accessible across the AppDomain, so this is a non-issue.

tarekahf:

2. With regards to Developing Business Objects in DLLs and deploying them to a Web Server for use by other applications with direct reference, when do you have to worry about making the DLL Thread Safe ? Is it necessary to write your DLLs to be Thread Safe ? Do you have always to reference to Thread Safe DLLs in your web applications ?

Typically you do not need to make your assemblies thread-safe - other than your static/Shared methods (because they are global to the AppDomain).

The exception would be if you intend to put any objects in a position where they'd be global to the AppDomain - then you'd have to devise a locking scheme for those objects. That is quite rare and should be avoided.

tarekahf:

3. Is CSLA.NET DLL Thread Safe ?

Tarek.

The static/Shared methods in CSLA .NET are thread-safe. Otherwise no. Like 99.9% of the .NET framework, CSLA .NET is not thread-safe.

tarekahf replied on Monday, April 21, 2008

So, the bottom line, is that even when you are developing Web Services, if the logic of the Web Services is using object instances that are shared across the AppDomain, then you still need to implement some kind of locking mechanism to avoid Data Corruption during update due to Multi-threading ?


Also, this means that there is no difference in terms of Multi-threading worries between using Web Service and direct reference to DLLs in your Web Application. I mean, that if the process is using object instances that are shared across the AppDomain then using the Web Service to implement such process will not solve this problem automatically, correct ?

Tarek.

RockfordLhotka replied on Monday, April 21, 2008

Correct, if you share an object instance across multiple threads then you must implement some sort of locking protocol.

 

Fortunately that is a pretty rare thing, except perhaps for cached read-only objects. In that case you only really need to worry if you are using property-level authorization (CanReadProperty()) because that bit of behavior is obviously per-user.

 

Rocky

 

From: tarekahf [mailto:cslanet@lhotka.net]
Sent: Monday, April 21, 2008 6:05 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: RE: How to build a Business Object using CSLA.NET to access data from 2 different Databases.

 

So, the bottom line, is that even when you are developing Web Services, if the logic of the Web Services is using object instances that are shared across the AppDomain, then you still need to implement some kind of locking mechanism to avoid Data Corruption during update due to Multi-threading ?


Also, this means that there is no difference in terms of Multi-threading worries between using Web Service and direct reference to DLLs in your Web Application. I mean, that if the process is using object instances that are shared across the AppDomain then using the Web Service to implement such process will not solve this problem automatically, correct ?

Tarek.

tarekahf replied on Monday, May 05, 2008

OK, good news. I received the book last week, and did more work with CSLA.

I have some issue raised by my colleague about using/re-using connections.

In order to be more clear and efficient, I have created a new thread here:

http://forums.lhotka.net/forums/23322/ShowThread.aspx#23322

I hope I can get your feedback on this matter.

Tarek.

Copyright (c) Marimer LLC