使用EF5 implementation of SharpRepository,我怎麼能使用RepositoryFactory時共享的DbContext躋身IRepository的不同instatiations?SharpRepository EF5,如何共享的DbContext
代碼片段:
using SharpRepository.Repository;
public class PersonManager()
{
private IRepository<Domain.PersonIdentifier, int> personIdentifierRepository;
private IRepository<Domain.NextNumber, string> nextNumberRepository;
public PersonManager()
{
//HOW TO SHARE A SINGLE DBCONTEXT INSTANCE BETWEEN THESE TWO INSTANTIATIONS ??
this.personIdentifierRepository = RepositoryFactory.GetInstance<Domain.PersonIdentifier, int>();
this.nextNumberRepository = RepositoryFactory.GetInstance<Domain.NextNumber, string>();
}
}
Web.config文件:
<sharpRepository>
<repositories default="EF5Repo">
<repository name="EF5Repo" connectionString="MyContainer" factory="SharpRepository.Ef5Repository.Ef5ConfigRepositoryFactory, SharpRepository.Ef5Repository" />
</repositories>
<cachingProviders default="inmemory">
<cachingProvider name="inmemory" factory="SharpRepository.Repository.Caching.InMemoryConfigCachingProviderFactory, SharpRepository.Repository" />
</cachingProviders>
<cachingStrategies default="noCaching">
<cachingStrategy name="timeout" timeout="30" factory="SharpRepository.Repository.Caching.TimeoutConfigCachingStrategyFactory, SharpRepository.Repository" />
<cachingStrategy name="standardCachingStrategy" generational="true" writeThrough="true" factory="SharpRepository.Repository.Caching.StandardConfigCachingStrategyFactory, SharpRepository.Repository" />
<cachingStrategy name="noCaching" factory="SharpRepository.Repository.Caching.NoCachingConfigCachingStrategyFactory, SharpRepository.Repository" />
</cachingStrategies>
</sharpRepository>
感謝
感謝。事實上,我認爲直接實例化Ef5Repository將是目前唯一的可能性,但感謝您確認這一點。還要感謝把StructureMap的例子放在那裏,實際上我打算使用它。保持在這個非常有用的圖書館良好的工作 – tjeuten 2013-03-07 17:04:44
謝謝。我已經在這裏頭腦風暴,只需要找出最佳方法。這將是非常有用的,所以感謝您提出。 – 2013-03-07 17:09:36