Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's what I'm doing:

I am reading a file in BLL, which is sitting in the UI layer. Currently the application is using HttpContext.Current.Request.PhysicalApplicationPath to find the absolute path written in BLL. I feel this is not a good design and I am thinking that I should pass this information in some kind of structure to BLL or I could use a helper method to get that.

Please let me know which one is better and if there are any better solutions / suggestions. Please ask if you need more details.

share|improve this question
Why not just pass the absolute path to your BLL? I could be misunderstanding what you're asking, though. – Jeremy Heiler May 26 '12 at 16:03
up vote 1 down vote accepted

Just the mere fact that the business logic needs to load a file from the physical application path sounds a little dodgy to me.

But if that is really what you need, I would extract knowledge about file paths to a separate component.

public interface IFileLocations
    string FilePathWhereCriticalFilesAreFound { get; }

public class FileLocations
    public string FilePathWhereCriticalFilesAreFound
         return HttpContext.Current.Request.PhysicalApplicationPath;

Now your business logic only needs a reference to an IFileLocations instance, which could be configured in a DI container (if you use one).

An even better design could be that instead of the class returning a file path, it could open a file for you.

public interface IFileOperations
    Stream OpenCriticalSystemFile(string fileName);

This makes the business logic that depends on this file even more testable, as the code that depends on the file doesn't actually open the file. This allows you to create an in-memory file and serve that component during unit testing.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.