使用SharpRepository 的 EF5 实现,如何在使用 RepositoryFactory 时在 IRepository 的不同实例之间共享 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>
谢谢