使用Unity将服务注入控制器

时间:2013-01-29 14:30:45

标签: asp.net-mvc-3 wcf unity-container

我正在使用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();
    }

1 个答案:

答案 0 :(得分:1)

您可以使用custom lifetime manager来表示此依赖关系。我建议你使用Unity.MVC3 NuGet包注册一个自定义依赖项解析器和这个自定义生命周期管理器,允许你处理IDisposable资源。