Parameterized Constructor for Businessbase object

Parameterized Constructor for Businessbase object

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


Pieter posted on Monday, March 03, 2008

Hi All,

I have a class called Session that contains information about the user, database, server, etc.
I want to use this class rather than the Database module, as in the examples.

Is there a way that I can have a constructor on my Businessbase object with a session parameter and a property on the Businessbase called session that will store the passed session object?

The session object's connection string property will then be used in the DataPortal_Fetch, DataPortal_Create, etc. methods to get the connection string.

Any thoughts/suggestions will be appreciated.

Thanks in advance!

triplea replied on Monday, March 03, 2008

Why have a session class and not store this information in your custom Identity class (e.g. PTIdentity equivalent) and just query that on your DataPortal_XYZ methods?

I could only understand if the information might change for a single user during his session using your app. In that case why not pass it in as criteria in your GetObject static class? So for example you would have something like:

public static Customer GetCustomer(int id, Session session)
{
   return Dataportal.Fetch<Customer>(new CustomerCriteria(id,session));

private class CustomerCriteria
{
   private int _id;
   private Session _session;

   public int Id { get { return _id; } }
   public Session Session { get { return _session; } }

   public CustomerCriteria(int id, Session session)
   {
      _id = id;
      _session = session;
   }
}

protected override void DataPortal_Fetch(object criteria)
{
   <use the connectionstring property of your Session class to open the connection>
}

Finally, a last option would be to pass the Session object in your static "New" method so for example:

public static Customer NewCustomer(Session session)
{
   this._session = session;
}

And then you have your private member _session in your DataPortal_XYZ methods.

It depends what you want. Just dont use the constructors directly :-)

Pieter replied on Monday, March 03, 2008

Thanks for the response!

I'll give your PTIdentity idea a try.

JonnyBee replied on Monday, March 03, 2008

There is also the ApplicationContext object which allows you to store som config/context data and have it automatically transfered to a remoting/webservice server.

User and Roles shold be in the Identity and Principal object.

Look at the UserContext part of the object for your usage, such as Server, ConnectionString and others.

/Jonny

Copyright (c) Marimer LLC