|
@@ -2,9 +2,12 @@
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
+using Grpc.Extension.Abstract;
|
|
|
|
+using Grpc.Extension.AspNetCore;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
@@ -12,11 +15,18 @@ namespace TEAMModelOS.GRPC
|
|
{
|
|
{
|
|
public class Startup
|
|
public class Startup
|
|
{
|
|
{
|
|
|
|
+ private IConfiguration _conf;
|
|
|
|
+ public Startup(IConfiguration conf)
|
|
|
|
+ {
|
|
|
|
+ _conf = conf;
|
|
|
|
+ }
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
|
public void ConfigureServices(IServiceCollection services)
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
{
|
|
services.AddGrpc();
|
|
services.AddGrpc();
|
|
|
|
+ //添加Grpc扩展
|
|
|
|
+ services.AddGrpcExtensions(_conf);
|
|
}
|
|
}
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
@@ -38,6 +48,15 @@ namespace TEAMModelOS.GRPC
|
|
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
|
|
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
+ //CodeFirst的Grpc(会自动扫描TStartup所在程序集下的IGrpcService)
|
|
|
|
+ app.UseGrpcExtensions<IGrpcService>(options =>
|
|
|
|
+ {
|
|
|
|
+ //CodeFirst配制
|
|
|
|
+ options.GlobalPackage = "TEAMModelOS.GRPC";
|
|
|
|
+ options.ProtoNameSpace = "TEAMModelOS.GRPC";
|
|
|
|
+ })
|
|
|
|
+ //CodeFirst生成proto
|
|
|
|
+ .UseProtoGenerate("Protos", false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|