How should I be using IoC in this winform piece of code?

Posted by Pure.Krome on Stack Overflow See other posts from Stack Overflow or by Pure.Krome
Published on 2010-03-19T12:28:35Z Indexed on 2010/03/19 12:31 UTC
Read the original article Hit count: 174

Hi folks,

I've got a winform app in visual studio 2010. My app does the following

  • Get a list of files which I need to read the data then insert into a database.
  • For each file, read data and insert into DB.

So .. this is the code i have.

var list = _repository.GetFileList();
if (list != null)
{
    int i = 0;
    foreach(var file in list)
    {
       i++;
       var service = new MyService(i, _repository);
       service.ParseAndSave();
    }
}

So i was hoping to have a new repository for each 'service' i create.

Firstly, i'm not sure if I should be using IoC in this case. I believe I should be because then i don't need to tightly couple this winform to a repository.

Secondly, I've tried using a Singleton repo, which I don't want and can confirm that it kills that code (crashes with an exception).

Some other notes (which shouldn't impact this question) - Using Entity Framework for ASP.NET 4. - Using StructureMap for IoC

Can someone help, please?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about winform