-
-
Notifications
You must be signed in to change notification settings - Fork 112
Migrate from Casbin.NET v1.x to v2.0
Sagilio edited this page Jul 25, 2023
·
17 revisions
-
Replace
NetCasbin.*
toCasbin.*
-
Change other namespaces according to list:
Before Now NetCasbin.Abstractions
Removed NetCasbin.Persist
Casbin.Persist.Adapter.File
NetCasbin.Util
Casbin.Functions
NetCasbin.Extension
Casbin
-
Replace
Model
,Config
,Enforcer
toIModel
,IConfig
,IEnforcer
-
Replace create APIs according list:
Before ( -
means new API)Now Model.CreateDefault DefaultModel.Create/new DefaultModel Model.CreateDefaultFromText DefaultModel.CreateFromText/ DefaultModel.NewModelFromText Model.CreateDefaultFromFile DefaultModel.CreateFromFile/ DefaultModel.NewModelFromFile new Config new DefaultConfig new Policy - -
Now, all
RBAC API
,Management API
,RBAC API
,RoleManager API
will only returnIEnumerable<string>
instead ofList<string>
.
-
Replace type name according the list:
Before Now DefaultFileAdapter FileAdapter Effect PolicyEffect PolicyEffectType EffectExpressionType -
Removed type list:
Removed Reason CoreEnforcer / ICoreEnforcer Merge to Enforcer
/IEnforcer
InternalEnforcer APIs as extension methods ManagementEnforcer / IManagementEnforcer APIs as extension methods Model Migrate to DefaultModel
and addIModel
Policy Unused AbstractFunction / IPMatchFunc / KeyMatch2Func ... Unused FunctionUtility Unused
-
Replace
enforcer.Get*()
methods toenfocer.*
properties, for example:**Before ** ( -
means new API)Now enforcer.GetModel() enfocer.Mdoel enforcer.GetEffector() enfocer.Effector enforcer.GetAdapter() enfocer.Adapter enforcer.GetWatcher() enfocer.Watcher -
Replace Obsolete APIs:
-
GetImplicitRolesForUser
// Obsolete public List<string> GetImplicitRolesForUser(string name, params string[] domain); // Replacement public IEnumerable<string> GetImplicitRolesForUser(string name, string domain = null)
-
CoreEnforcer.NewModel
// Obsolete CoreEnforcer.NewModel(); CoreEnforcer.NewModelFromText(string text); CoreEnforcer.NewModelFromFile(string fileName); // Replacement DefaultModel.NewModel(); DefaultModel.NewModelFromText(string text); DefaultModel.NewModelFromFile(string fileName);
-
RoleManager
// Obsolete public List<string> GetRoles(string name, params string[] domain); public List<string> GetUsers(string name, params string[] domain); public bool HasLink(string name1, string name2, params string[] domain); public void AddLink(string name1, string name2, params string[] domain); public void DeleteLink(string name1, string name2, params string[] domain); // Replacement public IEnumerable<string> GetRoles(string name, string domain = null); public IEnumerable<string> GetUsers(string name, string domain = null); public bool HasLink(string name1, string name2, string domain = null); public void AddLink(string name1, string name2, string domain = null); public void DeleteLink(string name1, string name2, string domain = null);
-
Now, you can enjoy the v2.0 version and welcome to open an issue if you have any questions!