refact: 抽象出IChatRobotFactory接口
This commit is contained in:
parent
773ae07ee3
commit
091a07460a
|
@ -1,7 +1,7 @@
|
||||||
@page "/"
|
@page "/"
|
||||||
@using Frontend.Models
|
@using Frontend.Models
|
||||||
@using Katheryne.Services
|
@using Katheryne.Abstractions
|
||||||
@inject KatheryneChatRobotFactory ChatRobotFactory
|
@inject IChatRobotFactory ChatRobotFactory
|
||||||
|
|
||||||
|
|
||||||
<Layout>
|
<Layout>
|
||||||
|
|
27
Katheryne/Abstractions/IChatRobotFactory.cs
Normal file
27
Katheryne/Abstractions/IChatRobotFactory.cs
Normal 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();
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Katheryne.Abstractions;
|
||||||
using Katheryne.Services;
|
using Katheryne.Services;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
@ -9,6 +10,6 @@ public static class ServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
collection.AddSingleton<YamlDeserializerFactory>();
|
collection.AddSingleton<YamlDeserializerFactory>();
|
||||||
collection.AddSingleton<DefaultChatRobot>();
|
collection.AddSingleton<DefaultChatRobot>();
|
||||||
collection.AddSingleton<KatheryneChatRobotFactory>();
|
collection.AddSingleton<IChatRobotFactory, KatheryneChatRobotFactory>();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ using YamlDotNet.Serialization;
|
||||||
|
|
||||||
namespace Katheryne.Services;
|
namespace Katheryne.Services;
|
||||||
|
|
||||||
public class KatheryneChatRobotFactory
|
public class KatheryneChatRobotFactory : IChatRobotFactory
|
||||||
{
|
{
|
||||||
private readonly YamlDeserializerFactory _deserializerFactory;
|
private readonly YamlDeserializerFactory _deserializerFactory;
|
||||||
private readonly ILogger<KatheryneChatRobotFactory> _factoryLogger;
|
private readonly ILogger<KatheryneChatRobotFactory> _factoryLogger;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user