LifetimeScopeAccessor
using Castle.MicroKernel.Context;
using Castle.MicroKernel.Lifestyle.Scoped;
using System;
namespace Castle.MicroKernel.Lifestyle
{
public class LifetimeScopeAccessor : IScopeAccessor, IDisposable
{
public void Dispose()
{
CallContextLifetimeScope.ObtainCurrentScope()?.Dispose();
}
public ILifetimeScope GetScope(CreationContext context)
{
CallContextLifetimeScope callContextLifetimeScope = CallContextLifetimeScope.ObtainCurrentScope();
if (callContextLifetimeScope == null)
throw new InvalidOperationException("Scope was not available. Did you forget to call container.BeginScope()?");
return callContextLifetimeScope;
}
}
}