I have a permission checking code in application service and I would like to move it to the domain service as it is being used by more than one application services. In the current method, I get the permissions from the database and has implemented a cache so that the next time application does not get the permissions from the database. My question is that you recommend implementing cache in application service so if I move this method to the domain service then I will lose the functionality of cache. I can see following three options, can you help?
- I create a method in the domain service that simply calls this existing application service method (this way cache is already implemented in the application service), all application services call this new domain service function.
- Implement the method in the domain service and implement cache in the domain service (I don't know if it can be done in ABP architecture).
- Implment the method in the domain service with cache (this is NOT ideal).
5 Answer(s)
-
0
Hi @learner29
If you use IPermissionChecker, it already has cache implementation. You can just use it anywhere you want. Is it what you use to check permission?
-
0
Permission Checker is just an example, it could be something completely different as well, so what would be the best way for that. Please provide some example with code.
- I create a method in the domain service that simply calls this existing application service method (this way cache is already implemented in the application service), all application services call this new domain service function.
- Implement the method in the domain service and implement cache in the domain service (I don't know if it can be done in ABP architecture).
- Implment the method in the domain service with cache (this is NOT ideal).
-
0
Hi @learner29,
We already have similiar implementation in Core layer, see https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Friendships/Cache/UserFriendsCache.cs.
-
0
So, are you saying that I use item 2 from the list given below? If I use 1 from the list below, will it have any issues?
- I create a method in the domain service that simply calls this existing application service method (this way cache is already implemented in the application service), all application services call this new domain service function.
- Implement the method in the domain service and implement cache in the domain service (I don't know if it can be done in ABP architecture).
- Implment the method in the domain service with cache (this is NOT ideal)
-
0
Yes @leaner29, you can use cache manager in domain service just like @ismcagdas said. So
2 .Implement the method in the domain service and implement cache in the domain service
seems good.