服务解析/位置和参数
如何将参数传递给解析器来创建对象?
我有一个 UoW 对象,我想将其传递到数据服务对象中,我希望能够确保以特定顺序创建的数据服务对象是使用一个 UoW 对象创建的,
例如
using (var context = Resolver.GetService<IUoW>())
{
var dataService1 = Resolver.GetService<IDataService1>();
var dataService2 = Resolver.GetService<IDataService2>();
// do some stuff
context.Commit();
}
选项 1,将 IUoW 传递到解析器中.GetService 调用 - 不了解 IDataServiceX 实现的构造函数
选项 2,为 IUoW 添加属性到 IDataServiceX - 不设置它很容易完成,程序员如何知道需要设置此属性
How would you pass parameters to a resolver to create an object?
I have a UoW object which I want to pass into a data service objects, I want to be able to ensure that the data service objects created in a particular sequence are created using the one UoW object
for example
using (var context = Resolver.GetService<IUoW>())
{
var dataService1 = Resolver.GetService<IDataService1>();
var dataService2 = Resolver.GetService<IDataService2>();
// do some stuff
context.Commit();
}
Option 1, pass IUoW into the Resolver.GetService call
- there is no knowledge of the constructors for IDataServiceX implementations
Option 2, add a property to IDataServiceX for IUoW
- not setting it would be easily done, how would a programmer know this property was required to be set
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前已经通过实体框架实现了工作单元 (UoW) 和存储库模式。
实际上,UoW 抽象了 EF 上下文,存储库抽象了实体集。
在我的实现中,存储库是 UoW 的属性,这意味着管理存储库生命周期的不是 IoC 容器,而是 UoW 的责任。
在您的情况下,存储库被命名为服务,但也许同样适用。对于特定工作单元中存在的所有服务,IUoW 接口是否可以具有两个(或更多)属性?
I've previously implemented a Unit of Work (UoW) and Repository pattern over Entity Framework.
In reality the UoW abstracted the EF context, and the repositories abstracted the entity sets.
In my implementation of the Repositories were properties of the UoW, meaning it was not the IoC container that managed the life-cycle of the repositories, that was the responsibility of the UoW.
In your situation the repositories are named services, but maybe the same applies. Can the IUoW interface have two (or more) properties for all the services that exist within the specific unit of work?