locked
Using internal static DAL RRS feed

  • Question

  • User1982534726 posted

    I have designed an application and am wondering if this is the best architecture to use and whether there is any danger.

    In namespace Membership I have a public class, MembershipManager, which inherits from webservice

    public class MembershipManager() : System.Web.Services.Webservice

    The single public web method of this class often needs to read and write to a database.

    [WebMethod()]
    public string DoMembershipWork(...various parameters...)

    The database work is done by implementing, in the same namespace,an internal class

    internal class MembershipDataAccess

    which has a series of internal static methods for data access e.g.

    internal static bool UpdateMembership(MembershipManager m)

    The MembershipManager class accesses the data access class by calling the appropriate method with itself as a parameter
    e.g.

    MembershipDataAccess.UpdateMembership(this);

    Is this a good idea. This application will be processing many transactions simultaneously. Is there a danger of not being thread safe. Note also that sometimes the MembershipDataAccess class will return datasets to the MembershipManager class.

    Can anyone see any potential problems with this approach?

    Thanks in advance,

    GS

    Monday, January 4, 2010 11:13 PM

Answers

  • User2104673743 posted

    Hi there GreenSands:

    Well, using static methods is always dangerous (iMHO) because if no locks are implemented, concurrent users could have unexpected results if they use the same code at the same time.

    I suggest you run your site in debug mode, then open 2 browser windows and fire the same funcionality almost at the same time, when you debug this you will see both threads jumping to different lines in the same method code....

    This experiment could help you...

    Hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 5, 2010 12:15 PM

All replies

  • User2104673743 posted

    Hi there GreenSands:

    Well, using static methods is always dangerous (iMHO) because if no locks are implemented, concurrent users could have unexpected results if they use the same code at the same time.

    I suggest you run your site in debug mode, then open 2 browser windows and fire the same funcionality almost at the same time, when you debug this you will see both threads jumping to different lines in the same method code....

    This experiment could help you...

    Hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 5, 2010 12:15 PM
  • User1982534726 posted

    Thanks for the reply, Jportealas.

    Considering this, I've changed to non-static and just instatiate a the object instead. I was only using static as a convenient way of calling methods anyway.

    GS 

    Tuesday, January 5, 2010 9:57 PM