1

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

4

1 に答える 1

1

以前、Entity Frameworkに作業単位(UoW)とリポジトリパターンを実装しました。

実際には、UoWはEFコンテキストを抽象化し、リポジトリはエンティティセットを抽象化しました。

私のリポジトリの実装では、UoWのプロパティでした。つまり、リポジトリのライフサイクルを管理したのはIoCコンテナではなく、UoWの責任でした。

あなたの状況では、リポジトリはサービスという名前ですが、おそらく同じことが当てはまります。IUoWインターフェースは、特定の作業単位内に存在するすべてのサービスに対して2つ(またはそれ以上)のプロパティを持つことができますか?

于 2012-01-12T11:04:39.000 に答える