使用在使用Server.Mappath业务层 [英] Use Server.MapPath in Business Layer

查看:203
本文介绍了使用在使用Server.Mappath业务层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的业务层创建文件,并需要将它们保存在我的asp.net mvc的4 web前端的的App_Data 文件夹中。

My business layer creates files and needs to save them in the App_Data folder of my asp.net mvc 4 web frontend.

我可以使用使用Server.Mappath 在业务层,以获得的App_Data 文件夹的物理路径。但我想避免在业务层的引用的System.Web

I could use Server.MapPath in the business layer to get the physical path of the App_Data folder. But i want to avoid a reference to System.Web in the business layer.

还有没有其他的方法来获得路径的App_Data 在业务层?

Are there other ways to get the path to App_Data in business layer?

推荐答案

的正确方法处理这个是有表示层传递路径到业务层。

The correct way to deal with this is to have the presentation layer pass the path into the business layer.

要此换句话说,具有业务层的目的是创建的UI和业务流程之间关注点分离。如果强制业务流程了解的UI层,那么你就违反了担忧分离。

To put this another way, the purpose of having a business layer is to create a separation of concerns between the ui and business processes. If you force the business process to know about the ui layer, then you are violating that separation of concerns.

有一些你可以处理这种方式。当业务层构造,比如通过构造函数初始化或通过依赖注入你可以通过路径到业务层。或者你可以将它传递给方法调用。或者你可以创建某种形式的包含路径配置文件,您的业务层负载。

There are a number of ways you could deal with this. You could pass the path into the business layer when the business layer is constructed, such as via constructor initialization or through dependency injection. Or you could pass it to the method call. Or you could create some form of configuration file that your business layer loads that contains the path.

有很多的要对此不违反关注点分离的方式。

There are lots of ways of going about this that do not violate separation of concerns.

这篇关于使用在使用Server.Mappath业务层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆