Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:16:04+00:00 2026-06-17T04:16:04+00:00

Imagine that I have one method like below that is using some strategies to

  • 0

Imagine that I have one method like below that is using some strategies to create new products and persists them as a result in the Db.

And everything happens as a part of a Unit of Work.

(My concern and)Question :
My concern is it OK or preventable to pass the UnitOfWork instance as a parameter to strategies and Commit the changes in the root method?
How can I avoid passing the UnitOfWork instance as a parameter to strategies but still make them work as a part of unit of work?

(I don’t like the fact that someone can call .Commit inside strategy implementations by mistake -which I do not want)

public void DoTheJob(CustomerRequest req)
{

 var materialsPikcerStrategyFactory = new PickerStrategyFactory();
 var productionStrategyFactory = new ProductionStrategyFactory();

 var materialsPickerStrategy = materialsPikcerStrategyFactory.GetStrategy(req); 
 var productionStrategy = productionStrategyFactory.GetStrategy(req);

 using (var uow = new UnitOfWorkFactory() )
 {
    var materials = materialsPickerStrategy.PickMaterials(req, uow);
    var products = productionStrategy.CreateProductsWith(materials, uow);
    uow.Commit();
 }

}


puplic abstract class MaterialsPickerStrategy 
{

 // Picks some material entities from Db and modifies some of its properties before usage
 public abstract ICollection<Material> PickMaterials(CustomerRequest req, IUnitOfWorkFactory uow);

}

public abstract class ProductionStrategy
{
 // Gets the materials and creates some new instances by ADD'ing them to the repository
 public abstract void CreateProductsWith (ICollection<Material> materials, IUnitOfWorkFactory uow);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:16:05+00:00Added an answer on June 17, 2026 at 4:16 am

    It seems like your code is using only unit of work but not repositories. They are usually use together to solve your problem. Repository is responsible for fetching data from database or registering changes in current unit of work and unit of work is responsible for committing registered changes. That would allow you passing repositories to your strategies and strategy will not have access to unit of work.

    In terms of EF ObjectContext / DbContext can be considered as unit of work and ObjectSet / DbSet can be considered as repository. If you have custom unit of work and custom repositories they must all share single EF context instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask you: Imagine that you have a site and there
I am using Entity Framework and DevExpress 10.5 XtraGrid. Imagine that we have entities
I have 1 unit test method that needs several parameters. I would like to
Imagine that we have below code public class test { public void Condition(x,y) {
Imagine that you have a method with the following signature: public void DoSomething(Guid id)
I have changed one of my instance methods to a class method so that
Imagine that I have a form in a flash application with two fields, input1
Imagine that I have a nice Deck class, in the best OO fashion. It
Imagine that i have the following code: <a:repeat value=#{bean.getList()} var=x > <li class=la> <span>
imagine that I have a Form with 9 controls (TabbedStuffControl) in a 3x3 tile,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.