1. Soumya Pandey
  2. SnapDevelop
  3. Wednesday, 21 June 2023 21:04 PM UTC

Is there any way to auto include Microsoft.AspNetCore.Authorization, when scaffolding the Service/Controller from the Model. 

For Example :

Whenever I scaffold Controller/Service from Model, I get a controller with following Namespace... 

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System;
using System.Linq;

..........................

And each time, in order to enable authentication, I will have to include Microsoft.AspNetCore.Authorization explicitly!!!!

Instead of that, can we include Microsoft.AspNetCore.Authorization Namespace automatically at the time of scaffolding? like

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;

using Microsoft.AspNetCore.Authorization;


using System;
using System.Linq;

......................................

 

Thanks!!

 

Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Thursday, 22 June 2023 18:47 PM UTC
  2. SnapDevelop
  3. # 1

Hi Soumya,

Why do you want to add that namespace to your controllers? Is it to use the [Authorize] attribute on the class?
If that's the case, one way to shorten the steps required is making use of the IDE's autocompletion features.

This will automatically insert the correct using statement at the bottom of the list.

You can open this menu by pressing Ctrl + . (period) when the cursor (the keyboard cursor, not the mouse pointer) is over the [Authorize] token.

This would only count as a workaround, though. I think it could be very nice to have a single checkbox in the scaffolding options to mark the controller as "Requires authorization" which would automatically add the attribute and the using statement. For this, I suggest you submit an enhancement request ticket through our support portal so that our product team can consider adding this feature to SnapDevelop in the future.

 

Regards,
Francisco

Comment
  1. Soumya Pandey
  2. Thursday, 22 June 2023 18:57 PM UTC
Thanks for your valuable reply, Francisco!

Taking your suggestion, I will certainly add an enhancement request ticket for this "Requires Authorization" Feature. Thanks.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.