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 8161269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:27:47+00:00 2026-06-06T18:27:47+00:00

One of my viewmodels contains reference to Service Controller. I’ve implemented the IDisposable on

  • 0

One of my viewmodels contains reference to Service Controller.
I’ve implemented the IDisposable on this viewmodel.
Now, i am creating List of this viewmodel in some other viewModel.
Do i need to implement IDisposable on other viewmodel.

  • 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-06T18:27:49+00:00Added an answer on June 6, 2026 at 6:27 pm

    I’d back this up a step and ask how your view model gets ahold of this reference to ServiceController. Are you injecting it as a dependency? Does the ServiceController have a longer lifespan than the ViewModel? If the ViewModel is creating it, then the Disposable makes sense, but if you are injecting this dependency or it is somehow being shared among the instances of your “ViewModelA”, then it ought not to be up to that class to dispose of the ServiceController. I mean, it doesn’t make sense for you to invoke Dispose() on some object that might be legitimately in scope elsewhere.

    But, assuming this does make sense (you have some list of VMs creating their ServiceController internally), then whether or not ViewModelB needs to implement IDisposable depends on the lifetime of the ViewModelA instances. If these are persisted as class level variables then yes, probably, you should dispose of them in VMB’s IDisposable. If they are created, used and discarded in a method, then no need.

    Reasoning about IDisposable is really all about considering the lifetimes of your objects. It makes sense when you have some resource that needs to be released but is kept around for the duration of an instance’s lifetime. And, when this happens, you’ll want to invoke Dispose() in the same scope as you created it in (often, as mentioned by Ashish, with the “using” keyword).

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

Sidebar

Related Questions

I am looking to implement some throttling behavior into one of my viewmodels. It's
This came up during one of our retrospectives and wanted some additional feedback and
Right now I have a viewmodel that contains three lists of inputs; textboxinput, dropdownlistinput,
I have an MVVM application. In one of the ViewModels is the 'FindFilesCommand' which
I have senario in which one view and view has binding with multiple ViewModel.
one question about PHP Development. I am building up some Form Fields for Calculations.
I have got a collection of viewModels(InputViewModel) in an other viewModel(ScenarioManager). each InputviewModel has
I have an application where I have a main viewmodel whose view contains a
This is one of those scenarios where Paralysis by Analysis seems to have taken
I've been struggling with this problem for two weeks now. I've searched all over

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.