MicroService4Net快速搭建微服务(二)

本文是MicroService4Net微服务搭建系列的第二部分,主要介绍如何进行config的自定义配置,包括控制器的分离和控制器与Action的路由响应处理。通过实现IAssembliesResolver、IHttpActionSelector和IHttpActionInvoker接口,实现了对Controller和Action的解析与选择逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接上一篇:http://blog.youkuaiyun.com/joyhen/article/details/70244666

对于config的配置,进行了自定义处理,主要是控制器的分离,以及控制器和action路由响应处理,如下:

static void Main(string[] args)
        {
            const int apiport = 65511;
            var microService = new MicroService(
                    port: apiport,
                    serviceDisplayName: string.Format("直播系统API服务:{0}", apiport),
                    serviceName: "xxLivePlatform",
                    configure: x =>
                    {
                        x.Routes.MapHttpRoute(
                             name: "DefaultApi",
                             routeTemplate: "api/{controller}/{action}/{id}",
                             defaults: new { id = RouteParameter.Optional }
                        );
                        x.Services.Replace(typeof(IAssembliesResolver), new Custom.ControllerResolver());
                        x.Services.Replace(typeof(IHttpControllerSelector), new Custom.CHttpControllerSelector(x));
                        x.Services.Replace(typeof(IHttpActionSelector), new Custom.CControllerActionSelector());
                        x.Services.Replace(typeof(IHttpActionInvoker), new Custom.CControllerActionInvoker());
                        x.MessageHandlers.Add(new Custom.CDelegating
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值