//Scoped模式 public BaseService(IContext context) { this.context = context; this.repository = Repository <T> .Instance; this.collection = repository.GetCollection(); if (this.GetContext() != null && this.GetContext().IsUseCache) { cache = LocalCache <T> .Instance; RebuildCache(); } }
//Singleton模式 public BaseService(IContextRepository contextRepository) { this.contextRepository = contextRepository; this.repository = Repository <T> .Instance; this.collection = repository.GetCollection(); //if (this.GetContext() != null && this.GetContext().IsUseCache) //{ // cache = LocalCache<T>.Instance; // RebuildCache(); //} cache = LocalCache <T> .Instance; RebuildCache(); }