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

  • SEARCH
  • Home
  • 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 6199641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:13:34+00:00 2026-05-24T04:13:34+00:00

my Controllers usually consume one or two Services. In turn, I inject a same

  • 0

my Controllers usually consume one or two Services. In turn, I inject a same Unit of Work to these Services to use the same Context. That is:

public class TestController : Controller
{
    private UnitOfWork _unitOfWork;
    private Service1 _service1;
    private Service2 _service2;

    public TestControler()
    {
        _unitOfWork = new UnitOfWork();

        // here I inject the unit of work to the services.
        _service1 = new Service1(_unitOfWork);
        _service2 = new Service2(_unitOfWork);
    }
}

My questions:

  1. How should I implement unit testing? Should I inject the unit of work
    only, or unit of work and services too?
  2. How can I dispose the objects? Should I dispose the unit of work or
    the services (which in turn dispose the unit of work)?
  • 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-05-24T04:13:35+00:00Added an answer on May 24, 2026 at 4:13 am

    1.) all dependencies should be injected, so anything you are newing up in the controller, which for you would be your unit of work and two services. this will make testing work properly, as you’ll be able to mock all dependencies. actually, looking at it more, you shouldn’t be injecting the unitofwork class, as it is only a dependency of the services.

    2.) your services shouldn’t need disposing if the unit of work object is actually handling all the work. my suggestion would be to implement idisposable on the UnitOfWork class and put it in a using()

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

Sidebar

Related Questions

I have two view controllers that allow changes to the Address Book. The first
I've added 3 controllers, and for one of them the Index view doesn't work
I usually avoid Apple navigation patterns, especially stacking views. I tend to use one
It's my understanding that in order to move between xib files one usually uses
In methods of controllers, there are usually many checks for doing the right thing.
I have two controllers which share most of their code (but must be, nonetheless,
In models and controllers, we often use Rails macros like before_validation , skip_before_filter on
I have two view controllers in a tabbar which can both edit data. Therefore,
I am implementing view controllers that shall have different behaviour. They have a common
All the examples I've seen for overloading usually have only two methods of the

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.