示例#1
0
        public AspNetIdentiyAuthorizeRelay(AuthorizeRelayDbContext context)
        {
            // SetDb(context);

            AuthorizeRelayDbContext db = CallContext.GetData(efKey) as AuthorizeRelayDbContext;

            if (db == null)
            {
                _db = context;
                CallContext.SetData(efKey, _db);
            }
            else
            {
                _db = db;
            }
            if (_db == null)
            {
                throw new ArgumentOutOfRangeException("context值为null,没有初始化context。注意:调用前先调用AspNetIdentiyAuthorizeRelay(AuthorizeRelayDbContext context)");
            }
            _roleManager = new SysRoleManager(new RoleStore <SysRole, int, SysUserRole>(_db));
            _userManager = new SysUserManager <TUser>(new UserStore <TUser, SysRole, int, SysUserLoginProvider, SysUserRole, SysUserClaim>(_db));
        }
示例#2
0
        private static AuthorizeRelayDbContext SetDb(AuthorizeRelayDbContext contextDb)
        {
            //这里可以保证只实例化一次
            //即在第一次调用时实例化
            //以后调用便不会再实例化

            //第一重  == null
            if (_db == null)
            {
                lock (syncObject)
                {
                    //第二重  == null
                    if (_db == null)
                    {
                        _db          = contextDb;
                        _roleManager = new SysRoleManager(new RoleStore <SysRole, int, SysUserRole>(_db));
                        _userManager = new SysUserManager <TUser>(new UserStore <TUser, SysRole, int, SysUserLoginProvider, SysUserRole, SysUserClaim>(_db));
                    }
                }
            }
            return(_db);
        }
示例#3
0
 public AspNetIdentiyAuthorizeRelay(AuthorizeRelayDbContext db)
 {
     _db          = db;
     _roleManager = new SysRoleManager(new RoleStore <SysRole, int, SysUserRole>(_db));
     _userManager = new SysUserManager <TUser>(new UserStore <TUser, SysRole, int, SysUserLoginProvider, SysUserRole, SysUserClaim>(_db));
 }