namespaceAcme.BookStore{publicclassBook:AggregateRoot<Guid>,ISoftDelete{publicstringName{get;set;}publicboolIsDeleted{get;set;}//Defined by ISoftDelete}}
namespaceAcme.BookStore{publicclassBook:AggregateRoot<Guid>,ISoftDelete,IMultiTenant{publicstringName{get;set;}publicboolIsDeleted{get;set;}//Defined by ISoftDeletepublicGuid?TenantId{get;set;}//Defined by IMultiTenant}}
namespaceAcme.BookStore{publicclassMyBookService:ITransientDependency{privatereadonlyIDataFilter_dataFilter;privatereadonlyIRepository<Book,Guid>_bookRepository;publicMyBookService(IDataFilterdataFilter,IRepository<Book,Guid>bookRepository){_dataFilter=dataFilter;_bookRepository=bookRepository;}publicasyncTask<List<Book>>GetAllBooksIncludingDeletedAsync(){//Temporary disable the ISoftDelete filterusing(_dataFilter.Disable<ISoftDelete>()){returnawait_bookRepository.GetListAsync();}}}}
[注入] IDataFilter 服务到你的类中.
在 using 语句中使用 Disable 方法创建一个代码块,其中禁用了 ISoftDelete 过滤器(始终与 using 搭配使用,确保代码块执行后将过滤重置为之前的状态).