????????????????????????????????????????????????????????????У????????ζ??????????????????????????????????????????????????????????????????????????????????????????????????????“????API”????????????????????“???????????”????????????????л??????
???????????????????
??????????????????????????漰???????????????????????????????????????????????????????и????????д??????????????Ч??????????????????????????????????.NET???к??????????á????????????????????????????????????
???????????????????
??????????????????????????????????????????????????????????????????????????????н?????????????????

???????????????????
????????????DEMO?????????????????????????????Ihandler?????????????AHandler??BHandler??CHandler???????????????PipelContext????
public interface IHandler
{
PipelContext DoAction(PipelContext pipelContext);
}
public class AHandler : IHandler
{
private IHandler NextHandler { get; set; }
public AHandler(IHandler nextHandler)
{
NextHandler = nextHandler;
}
public PipelContext DoAction(PipelContext pipelContext)
{
bool isNext = (pipelContext.Flag < 20) ? true : false;
pipelContext.request = "AA";
Console.WriteLine("my is " + pipelContext.request);
if (NextHandler != null && isNext)
{
NextHandler.DoAction(pipelContext);
}
return pipelContext;
}
}
public class BHandler : IHandler
{
private IHandler NextHandler { get; set; }
public BHandler(IHandler nextHandler)
{
NextHandler = nextHandler;
}
public PipelContext DoAction(PipelContext pipelContext)
{
bool isNext = (pipelContext.Flag < 10) ? true : false;
pipelContext.request = "BB";
Console.WriteLine("my is " + pipelContext.request);
if (NextHandler != null && isNext)
{
NextHandler.DoAction(pipelContext);
}
return pipelContext;
}
}
public class CHandler : IHandler
{
private IHandler NextHandler { get; set; }
public CHandler(IHandler nextHandler)
{
NextHandler = nextHandler;
}
public PipelContext DoAction(PipelContext pipelContext)
{
bool isNext = (pipelContext.Flag < 5) ? true : false;
pipelContext.request = "CC";
Console.WriteLine("my is " + pipelContext.request);
if (NextHandler != null && isNext)
{
NextHandler.DoAction(pipelContext);
}
return pipelContext;
}
}
public class PipelContext
{
public PipelContext()
{
Key = Guid.NewGuid();
}
public Guid Key { get; set; }
public int Flag { get; set; }
public string request { get; set; }
public string respone { get; set; }
}
static void Main(string[] args)
{
IHandler ModuleC = new CHandler(null);
IHandler ModuleB = new BHandler(ModuleC);
IHandler ModuleA = new AHandler(ModuleB);
PipelContext p = new PipelContext();
while (true)
{
p.Flag = Convert.ToInt32(Console.ReadLine());
ModuleA.DoAction(p);
}
}
??????????
????????????????????????????????????и??????????????????????÷??????????????????????????????