-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending an ABP controller #7721
Comments
Duplicate: #7698 |
That sure isn't a duplicate. The solution provided doesn't solve the issue. The solution provided implements a visual kludge in swagger by using the same
How is that extending As a matter of fact, i don't see |
Both questions ask about extending an existing abp controller to add a new method. The only difference is that the other question also says they want to override an existing method. I would consider this a duplicate. The only thing missing from that code to allow you to 'extend' functionality is a constructor with the AppService for you to access the available app service methods. this will appear the same to any user of the system. public MyIdentityUserController(IIdentityUserAppService userAppService)
{
}
public Task<??> MyAdditionalMethod(SomeInput input)
{
return userAppService.DoSomething(input);
} I wouldn't call it 'kludge', it's not like using magic strings, or having 100 parameters for a method. I don't believe it has any effect on performance, nor is it a hack. I also believe it does solve the issue of extending the available API methods. May I ask in what tangible way this approach is not feasible for your needs? I am open to a better solution but I don't believe one exists - though I would be interested if one does 👍 😄 Please also refer to my latest comment on the other issue: #7698 (comment) |
What if i wanted to How do I do that? What I am saying is: you are simply creating a new controller. That's it. Your fix doesn't have anything to with inheritance, which is what we want to accomplish. We want to inherit from It seems ABP breaks a very basic inheritance pattern that OOP gives us. It seems. Which I highly doubt. So there is something we must be missing, which is why I opened an issue. I don't know how else explain it. |
Yep okay no problem, I will see if it is possible to do it the way you describe when I am next able to. I am curious too. Until then I think we will have to wait for a reply from ABP on the matter. I still think it is a duplicate though 😄 |
The issue you linked talked about swagger not working -- This isn't a swagger issue since you can't hit the new endpoint via Postman. I could just remove the mention of swagger in the question and the issue is still relevant. |
The linked issue started as a different issue but in the end turned out to be the exact same problem as you described in this ticket. I started the GitHub issue before I created that stack overflow issue. Your question sums up the exact same problem I am facing as of this moment. Also looking for a clean way to extend an existing controller with one or more functions and still being able to override in the same extended class. |
hi @sonicmouse
|
@maliming it is with version 3.3.2. I created a project to reproduce the issue. Created an empty project with the cli from 3.1.2 (3.3.2 didn't work anymore). Then I manually upgraded to 3.3.2 (also because abp update -v 3.3.2 for some reason isn't working anymore today). That is the only class I added. When you call the register from postman the overridden function gets called. The my-function endpoint always returns a 404. Also not visible in swagger |
Have you seen this? #5269 (comment) |
@maliming yes I have seen it. The overriding part isn't the problem. That does actually work. It is adding a new method that doesn't work |
I have had a look at the source code and I can see that derived controllers are removed when the application starts up, which will likely stop the additional actions in the derived controllers being registered. Lines 74 to 103 in 739db98
The log:
Not sure how this would be fixed though. |
See #7766 |
I know you can override an ABP controller: https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Overriding-Services#example-overriding-a-controller
But, how would you add an endpoint to the overridden controller? I have tried adding an endpoint and I can't hit it with Postman and it doesn't show up in swagger. For example:
How can I accomplish this?
The text was updated successfully, but these errors were encountered: