Created
January 4, 2011 11:05
-
-
Save agross/764657 to your computer and use it in GitHub Desktop.
HybridLifestyleManager.cs
This file contains hidden or 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
using System.Web; | |
using Castle.MicroKernel; | |
using Castle.MicroKernel.Lifestyle; | |
namespace FubuMVC.Container.Castle.ForIoC | |
{ | |
public class HybridLifestyleManager : AbstractLifestyleManager | |
{ | |
readonly PerThreadLifestyleManager _perThread; | |
readonly PerWebRequestLifestyleManager _perWebRequest; | |
public HybridLifestyleManager() | |
{ | |
_perWebRequest = new PerWebRequestLifestyleManager(); | |
_perThread = new PerThreadLifestyleManager(); | |
} | |
public override void Init(IComponentActivator componentActivator, IKernel kernel, global::Castle.Core.ComponentModel model) | |
{ | |
base.Init(componentActivator, kernel, model); | |
_perThread.Init(componentActivator, kernel, model); | |
_perWebRequest.Init(componentActivator, kernel, model); | |
} | |
public override void Dispose() | |
{ | |
_perThread.Dispose(); | |
_perWebRequest.Dispose(); | |
} | |
public override object Resolve(CreationContext context) | |
{ | |
if (HttpContext.Current == null) | |
{ | |
return _perThread.Resolve(context); | |
} | |
return _perWebRequest.Resolve(context); | |
} | |
public override bool Release(object instance) | |
{ | |
if (HttpContext.Current == null) | |
{ | |
return _perThread.Release(instance); | |
} | |
return _perWebRequest.Release(instance); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment