Created
July 13, 2014 21:00
-
-
Save StacyGay/9f83f0ba37e8146d5675 to your computer and use it in GitHub Desktop.
SessionContainerManager example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SessionContainerManager | |
{ | |
private const string HttpContextKey = "Container"; | |
private readonly IUnityContainer _container; | |
public SessionContainerManager(IUnityContainer container) | |
{ | |
_container = container; | |
} | |
public IUnityContainer GetContainer() | |
{ | |
var routeData = HttpContext.Current.Request.RequestContext.RouteData.Values | |
?? new RouteValueDictionary(); | |
var session = HttpContext.Current.Session; | |
var queryString = HttpContext.Current.Request.QueryString; | |
if (!routeData.Any() || session == null) | |
return _container; | |
var clientName = routeData["clientName"] as string; | |
if (String.IsNullOrEmpty(clientName) || clientName.Contains("error")) | |
return _container; | |
var childContainer = session[clientName + HttpContextKey] as IUnityContainer; | |
if (childContainer != null && childContainer.IsRegistered<IConfig>()) | |
{ | |
// Make any additional adjustments based on the request parameters here | |
// MakeRequestAdjustments(childContainer, routeData); | |
return childContainer; | |
} | |
session[clientName + HttpContextKey] = childContainer = _container.CreateChildContainer(); | |
var extensionLoader = childContainer.Resolve<ExtensionLoader>(); | |
extensionLoader.LoadExtensions(clientName); | |
// MakeRequestAdjustments(childContainer, routeData); | |
return childContainer; | |
} | |
public void DisposeContainer() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment