I am using ABP Boilerplate 6.0 and have integrated NRules with our platform.
- I am able to get the rule below to work, but the issue is that I cannot use the injected ‘_questionResponseRepository’ within the rule condition, because only after the rule criteria are met, does the resolution of dependencies take place.
- I would like to use ‘_questionResponseRepository’ to get from the database a list of keywords and use those words in the Rule match condition
The Calling code
public WasteManagementManager(
IRepository<WasteBirthCertificateBlock, long> wasteBirthCertificateBlockRepository,
IRepository<WasteBirthCertificateChain, long> wasteBirthCertificateChainRepository,
ISession nRuleSession,
ISessionFactory nRuleSessionFactory,
ILogger log
)
{
_wasteBirthCertificateBlockRepository = wasteBirthCertificateBlockRepository;
_wasteBirthCertificateChainRepository = wasteBirthCertificateChainRepository;
_nRuleSession = nRuleSession;
_nRuleSessionFactory = nRuleSessionFactory;
_log = log;
}
public void Trigger()
{==>
When I am in debug, _questionResponseRepository is NOT NUll. I'm trying inject it as a fact but that is not property injection .. I'm just trying one way or the other to get it working
_nRuleSession.Insert(_questionResponseRepository);
_nRuleSession.Fire();
}
The Rule code
namespace SagerSystems.AI.WasteManagements.NRules
{
[Name("Track Explosive Substances Rule")]
public class TrackExplosiveSubstancesRule : Rule
{
private string[] _listOfExplosiveKeyWords = new string[] { "H3O", "N2" };
public IRepository<QuestionResponse, long> _questionResponseRepository { get; set; }
public TrackExplosiveSubstancesRule()
{
**This does NOT work** (the value remains null)
Dependency()
.Resolve(() => _questionResponseRepository);
}
public override void Define()
{
*This does work* but only after the rule fires)
Dependency()
.Resolve(() => _questionResponseRepository);
When()
.Match(() => questionResponseDto, c => CheckKeyWord(c));
Then()
.Do(ctx => Console.WriteLine(“Test Condition Works”))
}
private bool CheckKeyWord(QuestionResponseDto questionResponseDto)
{
==> How do I user ‘questionResponseRepository’
var isKeyWord=
_listOfExplosiveKeyWords.Any(c => questionResponseDto.QuestionText.Contains(c));
return isKeyWord;
}
}
}