diff --git a/Frontend/Pages/Index.razor b/Frontend/Pages/Index.razor index 2768761..2a17ff5 100644 --- a/Frontend/Pages/Index.razor +++ b/Frontend/Pages/Index.razor @@ -1,7 +1,7 @@ @page "/" @using Frontend.Models -@using Katheryne.Services -@inject KatheryneChatRobotFactory ChatRobotFactory +@using Katheryne.Abstractions +@inject IChatRobotFactory ChatRobotFactory diff --git a/Katheryne/Abstractions/IChatRobotFactory.cs b/Katheryne/Abstractions/IChatRobotFactory.cs new file mode 100644 index 0000000..d8b7127 --- /dev/null +++ b/Katheryne/Abstractions/IChatRobotFactory.cs @@ -0,0 +1,27 @@ +using Katheryne.Exceptions; + +namespace Katheryne.Abstractions; + +/// +/// 聊天机器人接口 +/// +public interface IChatRobotFactory +{ + /// + /// 当前使用的语法文本 + /// + public string GrammarText { get; } + + /// + /// 设置当前机器人使用的文法 + /// + /// 文法字符串 + /// 编译文法失败抛出的异常 + public void SetGrammar(string grammarText); + + /// + /// 获得聊天机器人 + /// + /// 使用当前文法的机器人 + public IChatRobot GetRobot(); +} \ No newline at end of file diff --git a/Katheryne/ServiceCollectionExtensions.cs b/Katheryne/ServiceCollectionExtensions.cs index e4bbd1c..a2a2b55 100644 --- a/Katheryne/ServiceCollectionExtensions.cs +++ b/Katheryne/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using Katheryne.Abstractions; using Katheryne.Services; using Microsoft.Extensions.DependencyInjection; @@ -9,6 +10,6 @@ public static class ServiceCollectionExtensions { collection.AddSingleton(); collection.AddSingleton(); - collection.AddSingleton(); + collection.AddSingleton(); } } \ No newline at end of file diff --git a/Katheryne/Services/KatheryneChatRobotFactory.cs b/Katheryne/Services/KatheryneChatRobotFactory.cs index 2206bbb..43af940 100644 --- a/Katheryne/Services/KatheryneChatRobotFactory.cs +++ b/Katheryne/Services/KatheryneChatRobotFactory.cs @@ -6,7 +6,7 @@ using YamlDotNet.Serialization; namespace Katheryne.Services; -public class KatheryneChatRobotFactory +public class KatheryneChatRobotFactory : IChatRobotFactory { private readonly YamlDeserializerFactory _deserializerFactory; private readonly ILogger _factoryLogger;