开发者

Substitute for Spring's init-method and destroy-method attributes in Unity

开发者 https://www.devze.com 2023-01-13 22:42 出处:网络
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 .

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号