Casbin.net Breaking changes while migrating from V1.13.0 to V2.9.1 - Enforcer class
I am trying to migrate Casbin.net package from V1.13.0 to V2.9.1. My Enforcer class used to look like this in the previous version.
public class CustomEnforcer : Enforcer
{
public CustomEnforcer() : this("", "")
{
}
public CustomEnforcer(string modelContent, string policyContent) : this(NewModel(modelContent), new DefaultFileContentAdapter(policyContent))
{
}
public CustomEnforcer(Model m, IAdapter adapter)
{
SetAdapter(adapter);
SetWatcher(null, false);
SetModel(m);
FunctionMap.LoadFunctionMap();
EnforcerOptions enforcerOptions = new EnforcerOptions()
{
};
Initialize(enforcerOptions);
if (this.adapter != null)
{
LoadPolicy();
}
}
}
I have changed it like this.
public class CustomEnforcer : Enforcer
{
public CustomEnforcer() : this("", "")
{
}
public CustomEnforcer(string modelContent, string policyContent)
{
Model = DefaultModel.CreateFromText(modelContent);
Adapter = new FileAdapter(policyContent);
}
}
is this correct? Do I need to do anything else? earlier version had a separate class with the implementation of DefaultFileContentAdapter. Do we need this in the latest version?
@sagilio @sociometry @AsakusaRinne
@shrey-shah why create two issues? https://github.com/casbin/Casbin.NET/issues/367
@shrey-shah why create two issues? #367
It looks like two different issues
Here is a sample for this issue.
public class CustomEnforcer : Enforcer
{
public CustomEnforcer(string modelText, string policyText)
: base(DefaultModel.CreateFromText(modelText),
new FileAdapter(ReadPolicyText(policyText)))
{
}
private static MemoryStream ReadPolicyText(string policyText)
{
return new MemoryStream(Encoding.UTF8.GetBytes(policyText));
}
}
my model and policy are like this: https://github.com/casbin/Casbin.NET/issues/367#issuecomment-2333998981 it gets passed in the string format itself. also, do we need the DefaultFileContentAdapter class now?
any update here?
my model and policy are like this: #367 (comment) it gets passed in the string format itself. also, do we need the DefaultFileContentAdapter class now?
It need not now. we will add new API for it.