37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
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)
|
|
{
|
|
}
|
|
|
|
}
|
|
}
|