The InMemoryRepositoryConfiguration
returns a new repository every time (see the source for the factory here), so it is not suitable for dependency injection if it's set up as transient (versus singleton).
If you're trying to use this in unit tests and are trying to stay in-memory, have a look at the CacheRepository
, I believe that will work how you'd like out of the box:
var sharpRepositoryConfiguration = new SharpRepositoryConfiguration();
sharpRepositoryConfiguration.AddRepository(new CacheRepositoryConfiguration("inmemory"));
sharpRepositoryConfiguration.DefaultRepository = "inmemory";
var repo = sharpRepositoryConfiguration.GetInstance<Account>().Add(new [] { .... });
return new StructureMapDependencyResolver(sharpRepositoryConfiguration);
It uses an InMemoryCachingProvider
by default, which uses the MemoryCache
for persistence. Add a prefix to the CacheRepositoryConfiguration
constructor if you have more repositories to avoid them stomping on each other.