Пример #1
0
        public IDisposable CreateRequestScope()
        {
            var requestContextRegistrations = new RequestContextRegistrations(_globalRegistrations);

            ContextStore.Add(CTX_REGISTRATIONS, requestContextRegistrations);

            return(new ActionOnDispose(() =>
            {
                _lifetimeManagers[DependencyLifetime.PerRequest].EndScope();
                requestContextRegistrations.Dispose();
                ContextStore.Remove(CTX_REGISTRATIONS);
            }));
        }
Пример #2
0
        public IDisposable CreateRequestScope()
        {
            if (ContextStore == null)
            {
                throw new DependencyResolutionException("Cannot resolve per-request outisde of request scope.");
            }
            var requestContextRegistrations = new RequestContextRegistrations(_globalRegistrations);

            ContextStore[CTX_REGISTRATIONS] = requestContextRegistrations;

            return(new ActionOnDispose(() =>
            {
                _lifetimeManagers[DependencyLifetime.PerRequest].EndScope();
                requestContextRegistrations.Dispose();
                ContextStore[CTX_REGISTRATIONS] = null;
            }));
        }