业务层,服务层和3层架构

时间:2014-03-10 09:40:13

标签: architecture business-logic

我想获得一个3层架构:UI< -BLL< -DAL。

我的DAL是一个“超级”对象,可以处理不同的数据库技术,如sql server,mysql,ecc ..

这就是我认为的业务逻辑层:

/// <summary>
/// Customer entity
/// </summary>
public class Account
{
    public String Username;
    public String Email;
}


public class AccountService<T>
    where T : Account
{

    IEntitymanager entityManager;

    public AccountService(IEntitymanager entityManager)
    {
        this.entityManager = entityManager;
    }

    public void Register(T account, 
                         String confirmPw, 
                         String verificationEmailBody)
    {
        // Validate parameters...
        // Check email uniqueness...
        // then write  account to db...
        if (entityManager.Save<T>(account))
        {
            // Send verification email whit GUID
        }
    }

    public void Verify(String guid)
    {
        T account = entityManager.Get<T>(new Parameter("Guid", guid));
        // Verify account
    }
}

现在我对此有一些疑问:

  • 这是业务层的示例,还是服务层或 什么?
  • 验证业务逻辑中的输入是否正确?
  • 在Register方法中,创建了帐户?在UI层创建它是否正确(从输入表单读取值,创建帐户对象并将其传递给Register)?
  • 我的BLL可以通过entityManager访问Db是否正确?
  • 如果我想使用这种BLL构建客户端和Web GUI,我需要其他层吗?

1 个答案:

答案 0 :(得分:0)

您可以通过实现Repository模式(即每个RDBMS数据访问组件可以实现的一组公共接口)来实现对多个RDBMS技术的支持。

您的业务逻辑被隔离到一个单独的类中,但如果您不通过边界(即使用SOAP或REST)公开它们,那么您就没有真正的服务层。并非每个应用程序都需要服务层。这取决于您的要求和预计的系统未来增长。

验证可能具有挑战性。如果系统的输入仅来自UI,则UI中的验证应该足够。但是,如果您有服务层,那么您可能还需要将一些验证复制到业务层。

您可能需要参考本文以获得有关分层体系结构的更好视图 http://serena-yeoh.blogspot.com/2013/06/layered-architecture-for-net.html

您也可以从此处下载示例实现 http://layersample.codeplex.com/

相关问题