using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using SoapCore;
using System.Reflection;
namespace Kean.Infrastructure.Soap
{
///
/// 抽象 Soap 映射器
///
public abstract class SoapMapper
{
///
/// 映射 Soap 路径
///
/// 路由建造者
internal abstract void Map(IEndpointRouteBuilder endpointBuilder);
}
///
/// Soap 映射器
///
/// 服务类型
public sealed class SoapMapper : SoapMapper
{
/*
* 实现 Kean.Infrastructure.Soap.SoapMapper.Map 方法
*/
internal override void Map(IEndpointRouteBuilder endpointBuilder)
{
var path = typeof(T).GetCustomAttribute()?.Path;
if (string.IsNullOrEmpty(path))
{
path = $"/soap/{(typeof(T).Name.EndsWith("Service") ? typeof(T).Name[..^7] : typeof(T).Name).ToLower()}";
}
endpointBuilder.UseSoapEndpoint(options => options.Path = path.StartsWith('/') ? path : $"/{path}")
.WithMetadata(new SoapMetadata());
}
}
}