@@ -22,6 +22,10 @@ internal abstract class EntityTypeContainerService<TTreeEntity, TEntityContainer
2222
2323 protected abstract UmbracoObjectTypes ContainerObjectType { get ; }
2424
25+ protected abstract int [ ] ReadLockIds { get ; }
26+
27+ protected abstract int [ ] WriteLockIds { get ; }
28+
2529 protected EntityTypeContainerService (
2630 ICoreScopeProvider provider ,
2731 ILoggerFactory loggerFactory ,
@@ -42,6 +46,7 @@ protected EntityTypeContainerService(
4246 public async Task < EntityContainer ? > GetAsync ( Guid id )
4347 {
4448 using ICoreScope scope = ScopeProvider . CreateCoreScope ( autoComplete : true ) ;
49+ ReadLock ( scope ) ;
4550 return await Task . FromResult ( _entityContainerRepository . Get ( id ) ) ;
4651 }
4752
@@ -134,6 +139,7 @@ protected EntityTypeContainerService(
134139 public async Task < Attempt < EntityContainer ? , EntityContainerOperationStatus > > DeleteAsync ( Guid id , Guid userKey )
135140 {
136141 using ICoreScope scope = ScopeProvider . CreateCoreScope ( ) ;
142+ WriteLock ( scope ) ;
137143
138144 EntityContainer ? container = _entityContainerRepository . Get ( id ) ;
139145 if ( container == null )
@@ -178,6 +184,7 @@ protected EntityTypeContainerService(
178184 }
179185
180186 using ICoreScope scope = ScopeProvider . CreateCoreScope ( ) ;
187+ WriteLock ( scope ) ;
181188
182189 EntityContainerOperationStatus operationValidationStatus = operationValidation ( ) ;
183190 if ( operationValidationStatus != EntityContainerOperationStatus . Success )
@@ -212,9 +219,26 @@ protected EntityTypeContainerService(
212219 }
213220
214221 using ICoreScope scope = ScopeProvider . CreateCoreScope ( autoComplete : true ) ;
222+ ReadLock ( scope ) ;
215223 return _entityContainerRepository . Get ( treeEntity . ParentId ) ;
216224 }
217225
218226 private void Audit ( AuditType type , int userId , int objectId )
219227 => _auditRepository . Save ( new AuditItem ( objectId , type , userId , ContainerObjectType . GetName ( ) ) ) ;
228+
229+ private void ReadLock ( ICoreScope scope )
230+ {
231+ if ( ReadLockIds . Any ( ) )
232+ {
233+ scope . ReadLock ( ReadLockIds ) ;
234+ }
235+ }
236+
237+ private void WriteLock ( ICoreScope scope )
238+ {
239+ if ( WriteLockIds . Any ( ) )
240+ {
241+ scope . WriteLock ( WriteLockIds ) ;
242+ }
243+ }
220244}
0 commit comments