I register components in global.asax.I resolve in try block in every web method and release in finally block. I created a wrapper for container so that it is called directly only during registration. Web methods call this wrapper to resolve and release components. This try finally adds a lot of boilerplate code.
Am I doing right? If not how should I do it? I am using Castle Windsor.
[WebMethod]
public void SomeMethod()
{
ISomeComponent c = null
try
{
c = myContainer.ResolveSomeComponent();
c.Method();
}
finally
{
myContainer.Release(c);
}
}
I have found the solution. As it turns out I can configure my components as Per Web Request and then I don’t have to release them because they will be automatically released at the end of request.
You can find details in this article: http://devlicio.us/blogs/krzysztof_kozmic/archive/2010/08/27/must-i-release-everything-when-using-windsor.aspx