using Microsoft.Extensions.Logging;
using Surging.Core.Caching.Configurations;
using Surging.Core.CPlatform.Utilities;
using Surging.Core.EventBusRabbitMQ.Configurations;
using System;
namespace Service.A
{
public class Startup
{
public Startup()
{
var config = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory);
ConfigureEventBus(config);
//ConfigureCache(config);
}
public IContainer ConfigureServices(ContainerBuilder builder)
{
var services = new ServiceCollection();
ConfigureLogging(services);
builder.Populate(services);
ServiceLocator.Current = builder.Build();
return ServiceLocator.Current;
}
public void Configure(IContainer app)
{
app.Resolve<ILoggerFactory>()
.AddConsole((c, l) => (int)l >= 3);
}
#region 私有方法
/// <summary>
/// 配置日志服务
/// </summary>
/// <param name="services"></param>
private void ConfigureLogging(IServiceCollection services)
{
services.AddLogging();
}
private static void ConfigureEventBus(IConfigurationBuilder build)
{
build
.AddEventBusFile("eventBusSettings.json", optional: false);
}
/// <summary>
/// 配置缓存服务
/// </summary>
private void ConfigureCache(IConfigurationBuilder build)
{
build
.AddCacheFile("cacheSettings.json", optional: false);
}
#endregion
}
}
Service.A.Service 类库下新增AService.cs
using Surging.Core.ProxyGenerator;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Service.A.Service{
public class AService:ProxyServiceBase,IAService
{
public Task<string> SayHello(string name)
{
return Task.FromResult($"{name} say : hello");
}
}
}
新增IAService.cs
using Surging.Core.CPlatform.Ioc;
using Surging.Core.CPlatform.Runtime.Server.Implementation.ServiceDiscovery.Attributes;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Service.A.Service
{
[ServiceBundle("api/{Service}")] public interface IAService : IServiceKey
{
Task<string> SayHello(string name);
}
}其他类库和服务与以上代码基本无二,这里不在赘述。不清楚的可以留言
所有代码都处理好后,在Service.A、Service.B、Service.C项目上右键新增docker支持文件,然后会生成一下文件

修改其中的docker-compose.yml










