示例#1
0
        public async Task Invoke(HttpContext context)
        {
            IDisposable dbCtx  = DbContext.CreateContext(Settings.ConnectionString);
            IDisposable secCtx = null;

            WebSecurityUtil.Authenticate(context);
            var identity = (context.User as ErpPrincipal)?.Identity as ErpIdentity;

            if (identity != null)
            {
                secCtx = SecurityContext.OpenScope(identity.User);
            }

            await next(context);

            await Task.Run(() => {
                if (dbCtx != null)
                {
                    dbCtx.Dispose();
                }
                if (secCtx != null)
                {
                    secCtx.Dispose();
                }
            });
        }
示例#2
0
        public async Task Invoke(HttpContext context, IRequestService requestService)
        {
            var dbCtx = DbContext.CreateContext(Settings.ConnectionString);

            requestService.AddObjectToDispose(dbCtx);

            WebSecurityUtil.Authenticate(context);
            var identity = (context.User as ErpPrincipal)?.Identity as ErpIdentity;

            if (identity != null)
            {
                var securityContext = SecurityContext.OpenScope(identity.User);
                requestService.AddObjectToDispose(securityContext);
            }

            await next(context);
        }