I don't have a problem, but I'm trying to prevent a problem from occurring in the future and would like a little help figuring out the proper way to approach this. I have a vendor who will be posting XML to a webpage that I have created. This would happen potentially every 2 minutes. The web page will then read the XML posted and insert into a Database. Serializing the XML and inserting is not good enough so I have to do a little bit of parsing before I send the data to the database. I created a static class that looks like the following.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Accounting
/// </summary>
public static class Accounting
{
public static String currentFile = "";
public static List<string> PurchaseOrder = new List<string>();
public static List<string> item = new List<string>();
public static List<string> unitPrice = new List<string>();
public static List<string> shippingCharge = new List<string>();
public static List<string> handlingCharge = new List<string>();
public static List<string> discountAmount = new List<string>();
public static List<string> UOM = new List<string>();
public static List<string> invoiceNumber = new List<string>();
public static List<string> supplierNumber = new List<string>(); //{ get; set; }
public static List<string> supplierInvoiceNo = new List<string>();
public static List<string> account = new List<string>();
public static List<string> fund = new List<string>();
public static List<string> org = new List<string>();
public static List<string> prog = new List<string>();
public static List<string> activity = new List<string>();
public static List<string> location = new List<string>();
public static List<string> distributionType = new List<string>();
public static List<string> distributionValue = new List<string>();
public static List<int> sequence = new List<int>();
public static List<string> quantity = new List<string>();
public static List<string> dueDate = new List<string>();
}
This class is static because I need to operate on the variables from different methods. Now here is where things get tricky, I keep reading that if I use static variable in a .NET web application I will end up sharing the variable across sessions. This could potentially be a nightmare for me. so I looked into the singleton pattern and I have also found this Static variables in web applications solution throught stackover flow. I read that I should do something like this
public class SingletonPerRequest
{
public static SingletonPerRequest Current
{
get
{
return (HttpContext.Current.Items["SingletonPerRequest"] ??
(HttpContext.Current.Items["SingletonPerRequest"] =
new SingletonPerRequest())) as SingletonPerRequest;
}
}
}
My problem is that I don't know how can I convert my class to basically do what the above is doing. In other words how do I set class to follow this singleton request pattern. Forgive my stupidity if this does not make sense. My ultimate goal would be to have every request to the page have its own session of accounting variables and not get shared across session. Any help would be greatly appreciated.