mardi 22 septembre 2020

Why do we see the "IWorkContext" "WorkContext" object on a lot of web application project (.Net Core)?

1.Becasue web application project need to check the objects ownership of current users, we need to check every model, every controller method, even use at view. We should obey the DRY principle.

  1. only one location get current user, you can change logic any time not need touch others codes.

  2. WorkContext including current user / Language / Currency / Vendor / TaxDisplay / IsAdmin etc.

Solution: create an IWorkContext and DI it. WorkContext class implements the interface IWorkContext, and register it on container, then we can use it on controller , services , view etc.

refernce URL:

ASP.NET best practice for checking model's objects ownership

enjoin Coding!




Aucun commentaire:

Enregistrer un commentaire