views:

55

answers:

1

I've inherited a large asp.net website that relies heavily on session information.

There is a back-end system that feeds it necessary information as needed through web services, but the application itself has no database, and everything is kept in session through a bunch of Data Objects which are accessed directly throughout the entire application.

I eventually want to try to migrate the application to a true N-Tier architecture, and start using a database instead of session based data objects.

My question is, what is a recommended path to get to the desired architecture?

I'm thinking that an initial step would be to create a Data Access Layer for accessing the data objects. Once this is in place, I would then be able to replace the data objects with a database.

The problem is that the session Data Objects are directly accessed from everywhere in the application. Because these objects are stored in session, you can directly set any of their properties without anything controlling the data. This is done throughout the whole application.

For example, say you have a customer Data Object stored in session. If you wanted to modify this customer, all you have to do is to set a local variable to the object stored in session. You could then update anything in the object just by setting mylocalvar.LastName = "blah"; Your session object is now updated without doing anything else.

Has anyone done anything like this before, and has any ideas on steps I could use to accomplish it?

*note: I'm not looking to off-load the session data, but to re-architect how the data is saved and accessed.

+1  A: 

Sounds like a big job!

I guess the first step is to build an abstraction layer for your session information and refactor your code so that it depends on that instead of the session. Once you've done that, with your gui code now dependant only on the abstraction layer, you'll be able to pull out the session code out of the abstraction layer and replace it with data access code and your gui should be none the wiser.

Frank Tzanabetis
+1 My thoughts exactly - abstract it out; and whe you do, keep the Interface Segregation Principle in mind.
Adrian K
Yeah, it's going to be tricky for sure. What you laid out is the basic direction I was thinking of going. The biggest problem is that there aren't any standard data manipulation mechanisms in place, such as explicitly saving the data, transactions, etc. The application just sets a local (usually global) variable to an already existing object from session, and then directly updates it's properties as needed. Are you aware of any tricks that would help move from one design to the other?
AaronS
So at what point does the local/global variables get stored back into the session state after being manipulated? At that point, i'm guessing, would be where you'd do a "save" of the data in your new abstraction layer.
Frank Tzanabetis
Unfortunately, That's the problem. All you have to do is modify any property on the object and the session object is automatically updated. You don't need to do anything else. Take a look at the customer example in my original post. It shows how the data is manipulated.
AaronS
Doesn't sound like there's an easy way around that based on what you've described; I can't think of any suggestions apart from my original answer anyway. Committing to the database every time the gui sets a property doesn't really sound like a good idea, so i suppose that means going through all the code to pull all the data/business logic out of there. Sounds almost like a rewrite.
Frank Tzanabetis