c# - ASP Net Core StructureMap HybridLifecycle replacement -


i'm in process of updating library built asp.net mvc 5 use latest asp net core 1.0 using structuremap di. however, i've noticed hybrid lifecycle in structuremap legacy , no longer supported. there replacement lifecycle out there, or way same functionality?

for<sessioncontext>()     .lifecycleis<hybridlifecycle>()     .use<sessioncontext>(); 

i ended writing own asp net lifecycle class match same functionality of old hybrid lifecycle new asp .net core.

public class aspnetcorelifecycle : ilifecycle {      private readonly object maplock = new object();      public string description => "asp net core lifecycle object";      private readonly container container;     private dictionary<httpcontext, iobjectcache> contextmap = new dictionary<httpcontext, iobjectcache>();      public aspnetcorelifecycle(container cont) {         this.container = cont;      }      public void ejectall(ilifecyclecontext context) {          lock (maplock) {             foreach (var kvp in contextmap) {                 kvp.value.disposeandclear();             }              contextmap = new dictionary<httpcontext, iobjectcache>();         }     }      public iobjectcache findcache(ilifecyclecontext context) {          var accessor = container.getinstance<ihttpcontextaccessor>();          lock (maplock) {             if (!contextmap.containskey(accessor.httpcontext)) {                 contextmap.add(accessor.httpcontext, new lifecycleobjectcache());             }              return contextmap[accessor.httpcontext];         }     } } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -