Substitute for Spring's init-method and destroy-method attributes in Unity
I worked for about a year on a big Java based project which uses Struts2 for MVC support and Spring for DI, and now, because of a shift in company's management I have to migrate my whole project to .NET.
I started poking around with Unity and MVC2, and since I have to replicate my previous solution, I was wondering does Unity have a mecha开发者_开发技巧nism similar to Spring's init-method and destroy-method methods. Here's an example of a Spring bean that uses these methods:
<bean id="connectionService" class="com.dms.webclient.service.impl.ConnectionServiceImpl"
init-method="init" destroy-method="destroy"/>`
You can use Method Call Injection. For example:
public class MyObject
{
[InjectionMethod]
public void Initialize(IMyService1 s1, IMyService2 s2)
}
or, in configuration file:
<type type="MyObject">
<typeConfig>
<method name="Initialize">
<param name="s1" parameterType="IMyService1">
<dependency />
</param>
<param name="s2" parameterType="IMyService2">
<dependency />
</param>
</method>
</typeConfig>
</type>
AFAIK, there is no "destroy" method. And, i wonder which scenario you really need it.
精彩评论