Hi folks,
I'm using StructureMap DI/IoC and I've got is a generic InMemory repository. Works great. I was wondering if it's possible to define the initial data which each repository holds, when it's requested?
Now, the first reaction is to do this in the constructor of the class - but I'm using a Generic Repository .. so i don't know what type of class will be instantiated. Next, I could subclass the GenericRepository and then create a constructor - sure :) That would work .. but i was trying to avoid creating a single class for each repository, when the GenericRepository is more or less doing everything I want :) (yes, there's some specific instances which I do subclass, etc.. but lets keep this post, simple).
So, is there a way to say
- Create an instance of InMemoryGenericRepository when ever an IRepository is requested
- Now, call this static method (which populates that Repo instant) : Foo(IRepository repository) { ... } which of course passes in the instance that was just created by StructureMap.