c# - How IAclModule works -


I want to know how this class IAclModule actually works, I mean that this is the process passed Access to the user, or is it used every time the same example?

I ask because there are ways to slow down the default AuthorizeAttributeAclModule and XmlRolesAclModule because I need to implement my object.

> Thx.

The accelerated by DC (Dependency Injection) container is made while using the internal DI container, This is done immediately. However, using the internal or external di, the sitemap for the lifetime of an object (and therefore by the cache) is kept alive for being stored in the private area of ​​plugins class, which in turn is in the private sector, the sitemap class therefore, There is 1 instance per each sitemap, which by default only expires the cache (1 by default every 5 minutes).

AuthorizeAttributeAclModule has been tested very well and it has been optimized very well. However, it creates an example of the AuthorizeAttribute class for the respective controller class and each node , so if your controller or AuthorizeAttribute is doing a lot of work in any custom implementation builder, Can issues run?

To fix this, you should inject the dependency in each controller through the controller constructor instead of lifting heavy load inside the controller. If you use one, you can control the lifetime of dependency outside the controller. As shown in the example below, you can use the same example of IMyRepository for each instance of MyController while using this approach.

  Public class MyController: Controller {Public MyController (IMyRepository repository) {if (repository == empty) Repeat new logic ("Repository"); This.repository = repository; } Private Readonly IMIRPository Repository; Public Performance Index () {var items = this.repository.GetList () View refresh (item); }}  

This is a best practice for the design of your controllers, but in a pinch, you can also cache your dependencies if they are expensive to make, then each controller If you have been requested more than once, then become such a time-consuming consumer.

  Public class MyController: Controller {public MyController () {this.repository = this.GetOrCreateRepository (); } Private Readonly IMIRPository Repository; Private IMyRepository GetOrCreateRepository () {var key = "MyControllerRepository"; Var Results = HttpContext.Items [Key]; If (result == zero) {// If expensive dependence was not already created for this request, then the result is now = new MyRepository (); // Save the example in the request, so the next time that the controller is created, // it does not have to instantiate it again. HttpContext.Items [Key] = Results; } Return results; } Public Performance Index () {var items = this.repository.GetList () Returns view (item); In addition, if you have custom authoritative attribute (s), then you should make sure that they are authorizing the user or not, besides Microsoft does the same thing. 


Comments