Peter K said:
Well, I guess it kind of depends. This code was designed only to run in a
web-context really. How could it have been done better, when they want to
share things in the current session? Made a wrapper to the session to use
as the common store, and used configuration to tell them to use that
particular wrapper/common storage?
You can have something like this to make it easier for non-technical users:
public void RunSomeProcess()
{
HttpContext context;
//Get context from session here
RunSomeProcess(context);
}
public void RunSomeProcess(HttpContext context)
{
//Run process here
}
But to only leave the non parameterized version is asking for issues, as it
leaves you with no way to uncouple the library from the UI.
BTW, this is extremely common and comes from the fact that many developers,
when asked the question "What kind of apps are you building?" answer
ASP.NET, ASP.NET MVC, WPF, Windows Forms or Silverlight. When you think of
the UI as an application, you end up coupling more often than not.
When you start thinking of libraries as the app, or framework, you start
thinking about removing the tight coupling by providing another way.
To put this in perspective, I recently built a library to create short urls
from various sites. The signatures look like this:
public string ShortenUrl(string longUrl, string apiUrl, ICommunicator
communicator, string userName, string password)
{
}
I am passing in the communicator as ICommunicator. This provides two quick
benefits:
1. I can test using mocks
2. I am not tightly coupled to a particular communicator
A bit different than what you are talking about, as the coupling is directly
to the UI, but it is the same idea.
Now, how can you potentially solve your issue? Duplicate the HTTP context or
bind your application to the IIS process somehow. Not ideal, but these are
the cards you were dealt with.
Peace and Grace,
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Twitter: @gbworld
Blog:
http://gregorybeamer.spaces.live.com
********************************************************
| Think outside the box! |
********************************************************