IRepository>>和 SOA 结合在一起

发布于 2024-10-14 14:19:11 字数 1054 浏览 2 评论 0原文

我需要一些有关使用 IRepository<> 的帮助模式和 SOA 结合在一起。

我正在开发一个会计应用程序,其中包含非常复杂的业务逻辑。目前我使用 IRepository 作为 DAL,它只执行基本的 CRUD + 操作,例如提供 IQueryable 接口、一些缓存功能等。

在它之上,我有一个业务逻辑层,它扮演服务或外观层的角色(它们是同一件事吗?)。所有应用程序逻辑都封装在这里作为将由表示层使用的方法。

正如我所说,所有基本的 CRUD 都放置在存储库中,但进一步发生在 BusinessLogic 中,例如,我们的帐户存储库中可能只有这些基本方法:

public class AccountRepository
{
    public IList<Accounts> GetAll()
    {
        ...
    }

    public Accounts Get(int id)
    {
        ...
    }

    public IList<Accounts Where(Func<Accounts,bool> criteria)
    {
        ...
    }

    public Accounts Add(Accounts item)
    {
        ...
    }
}

但要获取具有特定号码的帐户,我们将拥有这样的服务:

public class AccountService
{
    AccountRepository repos;

    public Accounts FindByNumber(int AccountNumber)
    {
        return repos.Where(o=>o.AccountNumber == AccountNumber).FirstOrDefault();
    }
}

AccountService还可以有一个 CreateAccount() 方法,通过使用实体存储库在单个事务中添加多个实体(帐户、所有者等)。

现在我想知道我是否以正确的方式使用它们?或者我错过了一些要点?

i need some helps on using IRepository<> pattern and SOA together.

i'm developing an accounting application which includes very complex business logics. currently i'm using the IRepository as a DAL which only do the basic CRUD + things like providing an IQueryable interface, some caching features and so on.

on top of it, i have a BusinessLogic layer which play the role of Service or Facade layer (are they the same thing?). all of the application logics encapsulated here as methods which will be used by Presentation layer.

as i said all basic CRUD are placed in repositories but further that take place in BusinessLogic, for example we may only have these basic methods in our Account repository :

public class AccountRepository
{
    public IList<Accounts> GetAll()
    {
        ...
    }

    public Accounts Get(int id)
    {
        ...
    }

    public IList<Accounts Where(Func<Accounts,bool> criteria)
    {
        ...
    }

    public Accounts Add(Accounts item)
    {
        ...
    }
}

but to get an account with a specific number we would have a service like this :

public class AccountService
{
    AccountRepository repos;

    public Accounts FindByNumber(int AccountNumber)
    {
        return repos.Where(o=>o.AccountNumber == AccountNumber).FirstOrDefault();
    }
}

AccountService also could have a CreateAccount() method which add multiple entities (an account, an owner and ...) by using entities repository and in a single transaction.

now i want to know am i using them in a right way ? or did i miss some points ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉世弥音 2024-10-21 14:19:11

@sos00 问“你如何管理事务?我的意思是你在哪一层处理它们?(我想到引擎层)以及你如何在这个架构中实现它们”

在 ​​SOA 中,你永远不能完全确定您的调用链,因为您今天编写的服务明天将以不同的方式编排。

我遵循这个启发法;在每个服务的边界上,如果它传递给我并加入该事务,我将加入一个环境事务,如果不存在环境事务,我将成为新事务的根。这样我就可以确定我需要做的任何工作都是事务,并将传递到我拉入编排中的其他组件。

请参阅本文:将完整性构建到面向服务架构

@sos00 asked "what do you do for managing transactions ? i mean in which layer do you handle them ? (i think of Engine layer) and how do you implement them in this architect"

In a SOA, you can never be entirely certain of your call chain, as the services you write today will be orchestrated in a different way tomorrow.

I follow this heuristic; on the boundary of every service I will join an ambient transaction if it is passed to me and enlist into that transaction, if no ambient transaction is present I will become the root of a new transaction. This way I am certain that any work that I need to do is transaction and will be passed on to other components I pull into my orchestration.

See this article: Building Integrity into SOA

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文