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.
// *******
// *** How should the _repository be Injected??
// *******
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?
UPDATE
Oh, I forgot to mention. When i don't specify the lifecycle type (eg. Singleton, etc). my objects which i try to save, just don't save. (ie nothing is sent to the DB, looking at SQL Profiler). If i use a Singleton with one file ... it works. A singleton with 2+ files, then exception/crashes because of (internal EF) Primary Key conflicts with Entity Framework. So if i should be using a Singleton, then the issue must be with how i've setup my EF4 context.