I have an extension method on the HTTPPTIFICATION object to exclude my IoC container from the application.
I have 2 questions:
- Is my code really safe because my intention is that
- consider it the best practice to deal with the application status
The code is as follows:
PrivateContent String GlobalContainerKey = "Unity Container"; Public static IUnityContainer GetContainer (this HttpApplicationState application) {var Container = Application [GlobalContainerKey] as IUnityContainer; If (container == faucet) {try {application.Lock (); Container = Application [Global Container] as IUnityContainer; If (Container == blank) {Container = New Unity Container (); Application [Global Container] = Container; }} Finally {application.UnLock (); }} Return container; }
you
var container = IUnityContainer Application in the form of [Global Container];
Also in the lock, otherwise you can create a new container in many thread sequences.
Private contact string Global Container = "Unity Container"; Private cast object lock object = new object (); Public static IUnityContainer GetContainer (this HttpApplicationState application) {var IUnityContainer container = zero; Lock (lock object) {container = app [global container] as IUnityContainer; If (Container == blank) {Container = New Unity Container (); Application [Global Container] = Container; }} Return container; }
Comments
Post a Comment