Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule.YieldScope C# (CSharp) Method

YieldScope() static private method

Returns current request's scope and detaches it from the request context. Does not throw if scope or context not present. To be used for disposing of the context.
static private YieldScope ( ) : ILifetimeScope
return ILifetimeScope
		internal static ILifetimeScope YieldScope()
		{
			var context = HttpContext.Current;
			if (context == null)
			{
				return null;
			}
			var scope = GetScope(context, createIfNotPresent: true);
			if (scope != null)
			{
				context.Items.Remove(key);
			}
			return scope;
		}

Usage Example

示例#1
0
        public void Dispose()
        {
            var scope = PerWebRequestLifestyleModule.YieldScope();

            if (scope != null)
            {
                scope.Dispose();
            }
        }