BotSharp/BotSharp.Core/AgentStorage/AgentStorageServiceRegister.cs

49 lines
1.7 KiB
C#
Raw Normal View History

2018-10-12 02:42:56 +00:00
using BotSharp.Platform.Abstraction;
using BotSharp.Platform.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Core.AgentStorage
{
public class AgentStorageServiceRegister
{
public static void Register<TAgent>(IServiceCollection services)
where TAgent : AgentBase
{
services.AddSingleton<IAgentStorageFactory<TAgent>, AgentStorageFactory<TAgent>>();
services.AddSingleton<AgentStorageInMemory<TAgent>>();
services.AddSingleton<AgentStorageInRedis<TAgent>>();
2018-10-22 03:47:51 +00:00
services.AddSingleton<AgentStorageInFile<TAgent>>();
2018-10-12 02:42:56 +00:00
services.AddSingleton(factory =>
{
Func<string, IAgentStorage<TAgent>> accesor = key =>
{
if (key.Equals("AgentStorageInRedis"))
{
return factory.GetService<AgentStorageInRedis<TAgent>>();
}
else if (key.Equals("AgentStorageInMemory"))
{
return factory.GetService<AgentStorageInMemory<TAgent>>();
}
2018-10-22 03:47:51 +00:00
else if (key.Equals("AgentStorageInFile"))
{
return factory.GetService<AgentStorageInFile<TAgent>>();
}
2018-10-12 02:42:56 +00:00
else
{
throw new ArgumentException($"Not Support key : {key}");
}
};
return accesor;
});
}
}
}