1
我有很多服務,每個服務都有一些功能。幾乎每個功能都需要一個當前用戶需要執行的「角色」。使用需要角色在服務內權限的功能
有沒有比在每個方法的開頭放置下面的代碼更好的方法?如果我可以用Attributes來裝飾這些方法,那將會很整潔,但我不確定如何在這裏應用它們。
public void CreateTruck(TruckDto dto)
{
var currentUser = GetCurrentUser();
if (!currentUser.Can("CreateTruck"))
throw PermissionException("...");
// otherwise proceed normally
}
如果只有可能通過使用屬性注入代碼... – zmbq