Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I see it has already been answered but just thought I would point out that you are synchronising all the calls to GetContainer with your locking pattern. A call to Application.Lock() actually takes out a write lock on the applicationState which is a singleton object in your web application and you will see issues if you want to scale this.</p> <p>To tidy this up you could do a double checked lock. like this:</p> <pre><code> public static IUnityContainer GetContainer(this HttpApplicationState application) { IUnityContainer container = application[GlobalContainerKey] as IUnityContainer; if (container == null) { application.Lock(); try { container = application[GlobalContainerKey] as IUnityContainer; if (container == null) { container = new UnityContainer(); application[GlobalContainerKey] = container; } } finally { application.UnLock(); } } return container; } </code></pre> <p>I would also like to point out a neat pattern that we have used to ensure Controls and Pages have their Dependencies built up. We basically have a Generic PageBase and Generic ControlBase that all our pages and controls inherit from. I will just go into the pagebase as an example:</p> <pre><code>public abstract class SitePageBase&lt;T&gt; : SitePageBase where T : SitePageBase&lt;T&gt; { protected override void OnInit( EventArgs e ) { BuildUpDerived(); base.OnInit( e ); } protected void BuildUpDerived() { ContainerProvider.Container.BuildUp( this as T ); } } </code></pre> <p>Then in our Pages we can simply derive from Generic base and it will look after the build up.</p> <pre><code>public partial class Default : SitePageBase&lt;Default&gt; { [Dependency] public IContentService ContentService { get; set; } protected override void OnPreRender( EventArgs e ) { this.label.Text = ContentService.GetContent("labelText"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload