After doing some research for my own project, it appears the following is the only solution
In a Windows application context information can be stored in the AppDomain.CurrentDomain which inherits from System.MarshalByRefObject, which is completely different object hierarchy for the web world. So in order to have your application work accross both platforms you must create an abstract layer for your context and your application will interact with the abstract/interface object. To accomplish this you will need a factory object that determines what environment you are in and call the appropriate class to return the abstract context. Here is a code example in C#, error handling and comments were not included in order to keep the size of the post small. All you need to do is implement the concrete class for dealing with the web environment. Constructive critisism is welcome
using System
namespace iGoBusinessManager.Runtim
/// <summary
/// Summary description for ContextFactory that is used to determine what type of context I will be dealing with
/// This is a static call and will be used in the application as the following: ContextFactory.GetContext(
/// You can set this up as a singleton if you like
/// </summary
public class ContextFactor
public ContextFactory(
/
// TODO: Add constructor logic her
/
public static IApplicationContext GetContext()
// You would normally have code to dermine the what context I am in and create the appropriate object
// In this example I am just creating the WindowsContext class and returning it as IApplicationContext
return (IApplicationContext)Activator.CreateInstance(Type.GetType("WindowsContext"))
using System
namespace iGoBusinessManager.Runtim
/// <summary
/// Summary description for IApplicationContext
/// </summary
public interface IApplicationContex
object GetObject(string objectName)
bool SetObject(string objectName, object myObject)
using System
namespace iGoBusinessManager.Runtim
/// <summary
/// Summary description for WindowsContext
/// </summary
public class WindowsContext : IApplicationContex
public WindowsContext(
/
// TODO: Add constructor logic her
/
public object GetObject(string objectName)
return AppDomain.CurrentDomain.GetData(objectName)
public bool SetObject(string objectName, object myObject)
try
AppDomain.CurrentDomain.SetData(objectName, objectName)
return true
catch (Exception ex
//do something with the exceptio
//then return fals
return false
using System
using iGoBusinessManager.EntityObjects.Entities
namespace iGoBusinessManager.Runtim
/// <summary
/// Summary description for Sample
/// </summary
public class Sampl
public Sample(
/
// TODO: Add constructor logic her
/
public Customer _CurrentCustomer
get
IApplicationContext myContext = ContextFactory.GetContext()
return (Customer)myContext.GetObject("Customer")
set
IApplicationContext myContext = ContextFactory.GetContext()
myContext.SetObject("Customer", value)
----- Don wrote: ----
I tried using that, but when working with my Windows App accessing the DLL
the HttpContext.Current.Session resolves to Nothing. Is there some way t
initialize it? When I had my code working with just HttpContext.Current,
needed to put the following line at the start of my Windows app
HttpContext.Current = New HttpContext(Nothing, Nothing
to initialize it, so to speak (I imagine this is explicitly doing what, in
way, the environment is doing for my ASP.NET program). I don't know what t
do to initialize HttpContext.Current.Session at the start of my Windows app
though
- Do