public IEnumerable <string> Get() { var serviceProvider = Request.HttpContext.RequestServices; // 此处获取到的send与_send为同一个实例,表示在相同的scope; var send = serviceProvider.GetService(typeof(ISend)) as ISend; return(new string[] { _send.GetGuid(), send?.GetGuid() }); }
// GET: Values public ActionResult Index() { ViewBag.send1 = _send.GetGuid(); return(View()); }
// GET api/values public IEnumerable <string> Get() { var send = Request.GetDependencyScope().GetService(typeof(ISend)) as ISend; return(new string[] { _send.GetGuid(), send?.GetGuid() }); }