HttpContext in business objects

J

John

Hello everyone!

I've read many articles about asp.net, business and data layers, and none of
them seem to discourage the use of HttpContext specific variables in
non-HttpContext specific layers; relying on the presence of the HttpSession
or HttpRequest variables in the business layer for example.

From what I can gather, doing this prevents these layers from being reused
by different clients (winforms for example) since this context will not
exist.

If this is so, then why is it not more widely discouraged? Is there a
common methodology for providing context to lower level layers without tying
them to one particular client?

Thanks in advance.
 
K

Kevin Spencer

Uncle Chutney sez: Neither a follower nor a lender be.

What does this have to do with your question, you may ask? Well, you began
your question by remarking about a number of opinions you have been exposed
to with regards to general programming practices. In fact, these opinions
are rather ridiculous. For example, the question of whether to use Class
Libraries that refer to HttpContext or not is a pointless question in
general. In a specific application it would be relevant, but in general it
is not. Why? Because the requirements of applications vary from one to
another. In one context, using HttpContext in a Class Library might be a
good idea; in another, it might be a bad idea. Why? Because Class Libraries
serve a huge variety of purposes. And people who debate over the "general
validity" of such a practice are debating about nothing. There IS no
"general validity" of such a practice. There is only specific validity
within the context of a set of requirements of a project. A Class Library is
a set of tools. What tools are in the box, and what they do, is determined
by the needs of the application. Knowing how to put together a good set of
tools is certainly important. However, this requires a more detailed and
low-level understanding of the technologies involved, and the specific
requirements of your current project.

If, for example, you are working on a project that uses a Class Library
which you design that you want to be able to use with multiple projects, the
question of whether or not to use HttpContext in your classes is affected by
(for one) the question of whether or not you anticipate ever needing to use
this Class Library in an executable app that doesn't reside in a web server.
However, there are quite a variety of other considerations as well.

There are a lot of people out there with opionions about things, and the
more likely they are to share them, the more likely their opinions are to be
useless. Why? Because an opinion is a poor substitute for a fact. And the
more opinions one has, the less fact that person is likely to have. After
all, if one has fact, one has no need for opinion.

At least that's my opinion! ;-)

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top