IRepository>>和 SOA 结合在一起
我需要一些有关使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@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