Skip to content

Fix GetReasoner. #779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class NaiveReasoner : IRoutingReasoner
private readonly IServiceProvider _services;
private readonly ILogger _logger;

public string Name => "Naive Reasoner";

public NaiveReasoner(IServiceProvider services, ILogger<NaiveReasoner> logger)
{
_services = services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ public IRoutingReasoner GetReasoner(Agent router)
{
var rule = router.RoutingRules.FirstOrDefault(x => x.Type == RuleType.Reasoner);

if (rule == null)
{
_logger.LogError($"Can't find any reasoner");
return _services.GetServices<IRoutingReasoner>().First(x => x.Name == "Naive Reasoner");
}

var reasoner = _services.GetServices<IRoutingReasoner>().
FirstOrDefault(x => x.GetType().Name.EndsWith(rule.Field));

if (reasoner == null)
{
_logger.LogError($"Can't find specific planner named {rule.Field}");
_logger.LogError($"Can't find specific reasoner named {rule.Field}");
// Default use NaiveReasoner
return _services.GetRequiredService<NaiveReasoner>();
return _services.GetServices<IRoutingReasoner>().First(x => x.Name == "Naive Reasoner");
}

return reasoner;
Expand Down