San*_*ndy 9 business-logic-layer 3-tier n-tier-architecture
我去接受采访,并被要求出示我的业务层架构.我对3层架构有一些了解,但实际上不知道在面试官面前写什么.因此,假设我的项目涉及组织的员工,那么我会在那里写什么.它是我应该制作的任何类型的图表还是某些编码部分.我在C#framework 3.5工作.我真的不明白这个问题还有什么要提,所以如果需要的话请告诉我.谢谢.
编辑 我在winforms工作.我知道什么是业务层,但不知道告诉面试官什么,因为业务层有代码,显然我的项目有点大,所以有大量的代码.那我应该写在那里?
bal*_*dre 20
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
作为我正在创建的项目的实例:

PL是所有公开的服务,我的DAL处理对数据库的所有访问,我有一个处理2个版本服务的服务层,一个旧的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);
...
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我只是使用依赖注入来分离另一层的知识,就像在这一层(表示层,因为这是一个MVC项目中的控制器)它应该永远不关心如何调用服务,并且用户使用ServiceA而不是ServiceB......需要知道的是调用一个IService.ListAllProjects()会给出正确的结果.
您开始划分建议,如果服务连接中出现问题,您知道这与表示层无关,它是服务层(在我的情况下),它很容易修复,可以轻松部署新的service.dll而不是发布整个网站再次...
我还有一个帮助程序,它包含我在所有项目中使用的所有Business Objects.
我希望它有所帮助.