views:

48

answers:

1

Hi everyone.

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 mechanism 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"/>`

A: 

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.

onof
Thanks, Onof, for the info about the init method. The scenario in which I would use the destroy method is when I want to sever some connections when the lifetime of the container controlled instances ends. I.E. when a session ends, close connections to internal servers/ streams, etc.
Marre