I have the following class (part of it):
class SearchViewModel : BaseViewModel<SearchResultItem> { private readonly IDownloader _downloader; public SearchViewModel( IDownloader downloader) : base(model) { _downloader = downloader; } private void Download(object sender, DoWorkEventArgs e) { _downloader.Download(item); } }
I used the constructor injection for IDownloader, and it worked fine before multithreading came into my life.
_downloader has state, and I need to run _downloader.Download (item) in separate threads (User clicks download buttons on the search results page).
Purpose: _downloader.Download(item)
to _downloader.Download(item)
, a new instance of _downloader
should be initialized. I can use _container.Resolve(IDownloader)
, but that would ruin the principle of root composition.
I created a question to discuss a better solution , because I believe that direct initialization (new ()) or a reference to the container is not the answer.
source share