Hi there!
I have 2 questions about using CrudAppService:
- How can i use AbpAuthorizeattribute on CrudAppServiceclass? Overriding base methods is not good approach.
- How can i inherite CrudAppServiceclass from AppServiceBaseclass?
3 Answer(s)
-
0
Hi,
For your first question, you can create your version of CrudAppService and add attribute to it. For example:
[AbpAuthorize] public class MyCrudAppService<TEntity, TEntityDto> : CrudAppService<TEntity, TEntityDto, int> where TEntity : class, IEntity<int> where TEntityDto : IEntityDto<int> { protected MyCrudAppService(IRepository<TEntity, int> repository) : base(repository) { } }
For your second question, CrudAppService already implements AbpServiceBase. CrudAppServie inherits CrudAppServiceBase inherits ApplicationService inherits AbpServiceBase.
-
0
Thanks, ismcagdas.
You have misunderstood me, perhaps I asked a bad questions. I'll try to describe my questions in more detail.
- I have my AppServices, which simple inherited from CrudAppService without overriding methods.
public class EmpAppService : CrudAppService<Emp, EmpDto, long, GetAllEmpsInput>, IEmpAppService { }
Also i have custom permissions for read, update, delete my entities Emp. Should i override all base class (CrudAppService) methods in my EmpAppService for setting AbpAuthorize("permission") attribute to Get, Update and other methods?
- EmpAppService inheritance
EmpAppService : CrudAppService : ApplicationService : AbpServiceBase
But i have a base class in my app services layer named MyProjectAppServiceBase .
MyProjectAppServiceBase : ApplicationService
This class defined various methods like GetCurrentUserAsync, GetCurrentTenantAsync and my common methods, which i want to use in EmpAppService, but i can't because EmpAppService is not descendant of the MyProjectAppServiceBase class.
Ok, i can create MyProjectCrudAppServiceBase
EmpAppService : MyProjectCrudAppServiceBase : CrudAppService
and duplicate methods from MyProjectAppServiceBase, but it's not DRY :)
-
0
Hi,
For the first question, yes you need to override each method and add attributes on them. We have created an issue about it, you can follow this issue and delete your overrides when we finish this. <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1567">https://github.com/aspnetboilerplate/as ... ssues/1567</a>
For your second question, I think it is the only way for now :)