public virtual Enforcer?GetEnforcer() { if (_enforcer is not null) { return(_enforcer); } if (_options.Value.DefaultEnforcerFactory is not null) { _enforcer ??= _options.Value.DefaultEnforcerFactory(_modelProvider.GetModel()); return(_enforcer); } Model?model = _modelProvider.GetModel(); if (model is null) { throw new ArgumentException($"{_modelProvider.GetModel()} can not return null when {nameof(_options.Value.DefaultEnforcerFactory)} option is empty"); } string?policyPath = _options.Value.DefaultPolicyPath; if (policyPath is not null) { if (!File.Exists(policyPath)) { throw new FileNotFoundException("Can not find the policy file path.", policyPath); } _enforcer ??= new Enforcer(_modelProvider.GetModel(), new DefaultFileAdapter(policyPath)); return(_enforcer); } _enforcer ??= new Enforcer(_modelProvider.GetModel()); return(_enforcer); }
public virtual Enforcer?GetEnforcer() { if (_enforcer is not null) { return(_enforcer); } if (_options.Value.DefaultEnforcerFactory is not null) { _enforcer ??= _options.Value.DefaultEnforcerFactory(_modelProvider.GetModel()); return(_enforcer); } Model?model = _modelProvider.GetModel(); if (model is null) { throw new ArgumentException($"{_modelProvider.GetModel()} can not return null when {nameof(_options.Value.DefaultEnforcerFactory)} option is empty"); } _enforcer ??= new Enforcer(_modelProvider.GetModel()); return(_enforcer); }
public virtual Enforcer?GetEnforcer() { if (_enforcer is not null) { return(_enforcer); } if (_options.Value.DefaultEnforcerFactory is not null) { using IServiceScope scope = _serviceProvider.CreateScope(); _enforcer ??= _options.Value.DefaultEnforcerFactory(scope.ServiceProvider, _modelProvider.GetModel()); return(_enforcer); } Model?model = _modelProvider.GetModel(); if (model is null) { throw new ArgumentException($"GetModel method of {nameof(ICasbinModelProvider)} can not return null when {nameof(_options.Value.DefaultEnforcerFactory)} option is empty"); } string?policyPath = _options.Value.DefaultPolicyPath; if (policyPath is not null) { if (File.Exists(policyPath) is false) { throw new FileNotFoundException("Can not find the policy file path.", policyPath); } _enforcer ??= new Enforcer(_modelProvider.GetModel(), new DefaultFileAdapter(policyPath)); return(_enforcer); } _enforcer ??= new Enforcer(_modelProvider.GetModel()); return(_enforcer); }
public virtual Enforcer?GetEnforcer() { _enforcer ??= _options.Value.DefaultEnforcerFactory?.Invoke(_casbinModelProvider.GetModel());; return(_enforcer); }