文档: WiKi.
附一个 RBAC 的服务设计实现 地址: zero.
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.SetBasePath(Directory.GetCurrentDirectory());
config.AddJsonFile("config/server.json", true, true);
}).ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.ConfigureKestrel(options =>
{
var config = AppConfig.ServerOptions;
//使用http2协议
options.Listen(new IPEndPoint(IPAddress.Any, config.Port),
listenOptions => { listenOptions.Protocols = HttpProtocols.Http2; });
})
.UseStartup<Startup>();
});
}
public Startup(IConfiguration configuration)
{
AppConfig.Configuration = (IConfigurationRoot)configuration;
}
public void ConfigureServices(IServiceCollection services)
{
// Add things to the service collection.
services.AddGrpc(grpc => grpc.Interceptors.Add<HystrixCommandIntercept>());
}
public void ConfigureContainer(ContainerBuilder builder)
{
// Add things to the Autofac ContainerBuilder.
builder.AddCoreService().RegisterModules();
}
public void Configure(IApplicationBuilder app)
{
// Set up the application for development.
ServiceLocator.Current = app.ApplicationServices.GetAutofacRoot();
app.UseRouting();
app.UseKetchupServer();
}
"Server": {
"Name": "sample",//服务名称
"Ip": "127.0.0.1",//服务ip
"Port": "5003",//服务端口
"EnableHttp": true, //是否开启http
"Security": {
"Whitelist": "*", //白名单
"BlackList": "" //黑名单
}
}
"Consul": {
"ConnectionString": "127.0.0.1:8500",//consul 的链接地址
"IsHealthCheck": true//是否进行健康检查
}
"Consul": {
"ConnectionString": "127.0.0.1:8500",
"IsHealthCheck": true
}
QQ 交流群:592407137