Skip to content

Commit ee6e4d6

Browse files
author
hchen2020
committed
Add custom agent data directory.
1 parent 52600e8 commit ee6e4d6

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Agents.Settings;
2+
3+
public class AgentSettings
4+
{
5+
public string DataDir { get; set; }
6+
}

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ public partial class AgentService : IAgentService
66
{
77
private readonly IServiceProvider _services;
88
private readonly IUserIdentity _user;
9+
private readonly AgentSettings _settings;
910

10-
public AgentService(IServiceProvider services, IUserIdentity user)
11+
public AgentService(IServiceProvider services, IUserIdentity user, AgentSettings settings)
1112
{
1213
_services = services;
1314
_user = user;
15+
_settings = settings;
1416
}
1517

1618
public string GetAgentDataDir(string agentId)
1719
{
18-
var dir = Path.Combine("data", agentId);
20+
var dir = Path.Combine(_settings.DataDir, agentId);
1921
if (!Directory.Exists(dir))
2022
{
2123
Directory.CreateDirectory(dir);

src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using BotSharp.Abstraction.Conversations.Settings;
21
using Microsoft.AspNetCore.Builder;
32
using Microsoft.Extensions.Configuration;
3+
44
namespace BotSharp.Core;
55

66
public static class BotSharpServiceCollectionExtensions
@@ -12,6 +12,10 @@ public static IServiceCollection AddBotSharp(this IServiceCollection services, I
1212

1313
services.AddScoped<IAgentService, AgentService>();
1414

15+
var agentSettings = new AgentSettings();
16+
config.Bind("Agent", agentSettings);
17+
services.AddSingleton((IServiceProvider x) => agentSettings);
18+
1519
var convsationSettings = new ConversationSetting();
1620
config.Bind("Conversation", convsationSettings);
1721
services.AddSingleton((IServiceProvider x) => convsationSettings);

src/Infrastructure/BotSharp.Core/Using.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
global using BotSharp.Core.Conversations.Services;
1919
global using BotSharp.Core.Infrastructures;
2020
global using BotSharp.Core.Plugins;
21-
global using BotSharp.Core.Users.Services;
21+
global using BotSharp.Core.Users.Services;
22+
global using BotSharp.Abstraction.Agents.Settings;
23+
global using BotSharp.Abstraction.Conversations.Settings;

0 commit comments

Comments
 (0)