将依赖事件总线的发布订阅模式,改为直接调用的形式
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
public class WareHouseBasedControllerActivator : IControllerActivator
|
||||
{
|
||||
public object Create(ControllerContext context)
|
||||
{
|
||||
if(context == null) { throw new ArgumentNullException("context"); }
|
||||
var controllerType = context.ActionDescriptor.ControllerTypeInfo.AsType();
|
||||
//获取Controller实例
|
||||
var controller =context.HttpContext.RequestServices.GetRequiredService(controllerType);
|
||||
//判断是否继承了自定义Controller基类
|
||||
//if(controller is BaseWareHouseService basedWhSvc)
|
||||
//{
|
||||
// basedWhSvc.WareHouseSrv = context.HttpContext.RequestServices.GetRequiredService<IWareHouseService>();
|
||||
//}
|
||||
return controller;
|
||||
|
||||
}
|
||||
|
||||
public void Release(ControllerContext context, object controller)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user