一个3层架构是由3主层
每个
组成顶层只会询问下层而不会可以看到任何东西。
当他们问你您将如何建立你的BLL,你可以写这样的:
namespace Company.BLL
{
// let's create an interface so it's easy to create other BLL's if needed
public interface ICompanyBLL
{
public int Save(Order order, UserPermissions user);
}
public class Orders : ICompanyBLL
{
// Dependency Injection so you can use any kind of BLL
// based in a workflow for example
private Company.DAL db;
public Orders(Company.DAL dalObject)
{
this.db = dalObject;
}
// As this is a Business Layer, here is where you check for user rights
// to perform actions before you access the DAL
public int Save(Order order, UserPermissions user)
{
if(user.HasPermissionSaveOrders)
return db.Orders.Save(order);
else
return -1;
}
}
}
作为一个项目我创建的一个活生生的例子:
PL的都是公开的服务,我的DAL处理所有访问数据库,我hav即处理2个版本的服务的EA 服务层,旧ASMX和新的WCF服务,它们是通过Interface
自曝所以很容易让我选择在即时的用户将使用
什么样的服务
public class MainController : Controller
{
public IServiceRepository service;
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
...
if (thisUser.currentConnection.ws_version == 6)
// Use old ASMX Web Service
service = new WebServiceRepository6(url, ws_usr, ws_pwd);
else if (thisUser.currentConnection.ws_version == 7)
// Use the brand new WCF Service
service = new WebServiceRepository7(url, ws_usr, ws_pwd);
...
}
}
在上面的代码中,我只是使用依赖注入来分离其他层的知识,就像在这个层(表示层,因为这是一个MVC项目中的控制器),它永远不应该关心如何调用服务,并且用户使用ServiceA
而不是ServiceB
......它需要知道的是调用IService.ListAllProjects()
将提供正确的结果。
你开始划分建议,如果服务连接出现问题,你知道这与表示层无关,它是服务层(在我的情况下),它很容易修复,并且可以很容易地部署一个新的service.dll
而是再次发布整个网站...
我也有一个帮手,它包含我在所有项目中使用的所有Business Objects。
我希望它有帮助。
是否只显示您的业务层架构?是不是有一些背景?他有没有明确地问过你三层架构?如果没有上下文,你会被问到这个问题,你应该回答你有不同的架构适合不同的场景。 –
Isnt面试过了还是会有第二轮? :-) –
@Darin:他让我出现3层架构 – Sandy