Add custom agent data directory.
This commit is contained in:
parent
52600e804c
commit
ee6e4d61fb
|
|
@ -0,0 +1,6 @@
|
|||
namespace BotSharp.Abstraction.Agents.Settings;
|
||||
|
||||
public class AgentSettings
|
||||
{
|
||||
public string DataDir { get; set; }
|
||||
}
|
||||
|
|
@ -6,16 +6,18 @@ public partial class AgentService : IAgentService
|
|||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IUserIdentity _user;
|
||||
private readonly AgentSettings _settings;
|
||||
|
||||
public AgentService(IServiceProvider services, IUserIdentity user)
|
||||
public AgentService(IServiceProvider services, IUserIdentity user, AgentSettings settings)
|
||||
{
|
||||
_services = services;
|
||||
_user = user;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public string GetAgentDataDir(string agentId)
|
||||
{
|
||||
var dir = Path.Combine("data", agentId);
|
||||
var dir = Path.Combine(_settings.DataDir, agentId);
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using BotSharp.Abstraction.Conversations.Settings;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace BotSharp.Core;
|
||||
|
||||
public static class BotSharpServiceCollectionExtensions
|
||||
|
|
@ -12,6 +12,10 @@ public static class BotSharpServiceCollectionExtensions
|
|||
|
||||
services.AddScoped<IAgentService, AgentService>();
|
||||
|
||||
var agentSettings = new AgentSettings();
|
||||
config.Bind("Agent", agentSettings);
|
||||
services.AddSingleton((IServiceProvider x) => agentSettings);
|
||||
|
||||
var convsationSettings = new ConversationSetting();
|
||||
config.Bind("Conversation", convsationSettings);
|
||||
services.AddSingleton((IServiceProvider x) => convsationSettings);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,6 @@ global using BotSharp.Core.Agents.Services;
|
|||
global using BotSharp.Core.Conversations.Services;
|
||||
global using BotSharp.Core.Infrastructures;
|
||||
global using BotSharp.Core.Plugins;
|
||||
global using BotSharp.Core.Users.Services;
|
||||
global using BotSharp.Core.Users.Services;
|
||||
global using BotSharp.Abstraction.Agents.Settings;
|
||||
global using BotSharp.Abstraction.Conversations.Settings;
|
||||
Loading…
Reference in a new issue