ava-innersource / Liquid-Application-Framework-1.0-deprecated

Liquid is a framework to speed up the development of microservices
MIT License
25 stars 14 forks source link

Remove LightContext #205

Open bruno-brant opened 4 years ago

bruno-brant commented 4 years ago

As attested during the discussion on #198, the class LightContext has little semantic value for Liquid. It's a holder for a ClaimsPrincipal, just that.

Now that #204 removed the authorization code from LightWorker, LightContext is just used by LightController, and in the most weird manner:

https://github.com/Avanade/Liquid-Application-Framework/blob/2ebc7fa6608f943434837948558b7939f2864fb9/src/Liquid.Activation/Controller/LightController.cs#L31-L37

You can see all sorts of strange things in this code:

  1. LightControllerdefines both this GetContext method (which is private) and a protected field _context, so there are two ways of accessing a LightContextfrom the controller. However, upon further inspection, one can see that the field isn't ever written to.

  2. The method passes a IHttpContextAccessorto the LightContextconstructor. This is stored in a public field of the LightContext. Also, the User property is manually assigned to by the method with the User obtained from the HttpContext. The same user that is available through _httpContextAccessor, so we are effectively transmitting the same data twice.

  3. The domain shouldn't access HTTP context data. This is a violation of the responsibility of the domain.

For all those reasons, I suggest we obsolete and remove LightContext, replacing it with more semantic types when necessary.