我正在使用Unity向控制器注入wcf服务。但是我注意到没有办法关闭服务。在服务方法返回后,如何确保与服务的连接关闭?
public ITiers TierClient { get; set; }
public HomeController(ITiers tierClient)
{
TierClient = tierClient;
}
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
bool result = TierClient.CheckIfTierExiste("***", "***", null, true);
return View();
}
答案 0 :(得分:1)
您可以使用custom lifetime manager
来表示此依赖关系。我建议你使用Unity.MVC3
NuGet包注册一个自定义依赖项解析器和这个自定义生命周期管理器,允许你处理IDisposable
资源。