refact: 抽象出IChatRobotFactory接口

This commit is contained in:
jackfiled 2023-10-17 22:20:38 +08:00
parent 773ae07ee3
commit 091a07460a
4 changed files with 32 additions and 4 deletions

View File

@ -1,7 +1,7 @@
@page "/"
@using Frontend.Models
@using Katheryne.Services
@inject KatheryneChatRobotFactory ChatRobotFactory
@using Katheryne.Abstractions
@inject IChatRobotFactory ChatRobotFactory
<Layout>

View File

@ -0,0 +1,27 @@
using Katheryne.Exceptions;
namespace Katheryne.Abstractions;
/// <summary>
/// 聊天机器人接口
/// </summary>
public interface IChatRobotFactory
{
/// <summary>
/// 当前使用的语法文本
/// </summary>
public string GrammarText { get; }
/// <summary>
/// 设置当前机器人使用的文法
/// </summary>
/// <param name="grammarText">文法字符串</param>
/// <exception cref="GrammarException">编译文法失败抛出的异常</exception>
public void SetGrammar(string grammarText);
/// <summary>
/// 获得聊天机器人
/// </summary>
/// <returns>使用当前文法的机器人</returns>
public IChatRobot GetRobot();
}

View File

@ -1,3 +1,4 @@
using Katheryne.Abstractions;
using Katheryne.Services;
using Microsoft.Extensions.DependencyInjection;
@ -9,6 +10,6 @@ public static class ServiceCollectionExtensions
{
collection.AddSingleton<YamlDeserializerFactory>();
collection.AddSingleton<DefaultChatRobot>();
collection.AddSingleton<KatheryneChatRobotFactory>();
collection.AddSingleton<IChatRobotFactory, KatheryneChatRobotFactory>();
}
}

View File

@ -6,7 +6,7 @@ using YamlDotNet.Serialization;
namespace Katheryne.Services;
public class KatheryneChatRobotFactory
public class KatheryneChatRobotFactory : IChatRobotFactory
{
private readonly YamlDeserializerFactory _deserializerFactory;
private readonly ILogger<KatheryneChatRobotFactory> _factoryLogger;