So I am working on an existing website project that has a BLL layer with some functions that use physical file paths.

But now I am creating a console app that will be setup as a windows scheduled task that will call some of these functions and it is complaining about not having the existing files.

Sounds to me like this breaks all separation of concern principles. Is it best to have the app, MVC layer in the existing website project, or anything else that calls the BLL to pass the file/path it needs to the BLL instead of practically hardcoding it? Done a search and there are so many calls to Server.MapPath() for example.


It sounds like the functional layer of the library would benefit from a refactoring to separate the concerns of "getting data" and "processing data."

If both use cases involve file operations, then moving from hard-coded file names to accepting them as arguments would likely suffice and could be a short path to a functioning application.

Another option which is a bit more object-oriented is to change your library to use streams (this is the approach I would take). This is applicable to pretty much any program that accepts input (which is most of them). Call a function, pass in an input stream of some type. It might be backed by a file, it might not. Standard input, a socket, a static byte array, those could all back the stream. You did not specify a language, but pretty much all modern OO languages I know of support streams in some way.

This way, your web app could pass in a stream that reads those files, maybe using web-app specific API calls if necessary. Your console app could use a different method. As long as both data sources adhere to your platform's stream interface, none of that matters to the underlying library. All it cares about is that it can call a function on that stream to get data.

  • Thanks, gonna focus on refactoring. Like the simplicity of your first statement and breaking the concerns out. Will let you know how it goes. – SharpCode Oct 5 '17 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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