Question

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

Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top