tags:

views:

348

answers:

1

Hi All,

Having a bit of a headache with Unity XML configuration and generics. I have these files:

public interface IRepository<T> {}

public class OrderRepository : IRepository { }

public class DispatchOrderProcess
{
     public DispatchOrderProcess(IRepository<Order> repository) { }
}

I would like to inject the Order Repository into the DispatchOrderProcess class using Unity XML configuration. So far I have something like so:

   <type name="OrderRespository" type="Company.Project.Core.Interfaces.IRepository`1, Company.Project.Core" mapTo="Company.Project.Core.Repositories.OrderRepository, Company.Project.Core" />

   <type name="DispatchOrderProccess" type="Company.Project.Core.Interfaces.ISendAlertsProcess, Company.Project.Core" mapTo="Company.Project.Core.Processes.SendAlertsProcess, Company.Project.Core">
    <typeConfig>
     <constructor>
      <param name="orderRepository" parameterType="Company.Project.Core.Interfaces.IRepository`1, Company.Project.Core">
       <dependency name="OrderRespository"/>
      </param>
     </constructor>
    </typeConfig>
   </type>
  </types>
 </container>
</containers>

A: 

...and your problem is?

I have done some stuff with generics quite recently though and I had some trouble with the syntax. Apparently I neaded to tell unity what the typeof T was, something like:

type="Company.Project.Core.Interfaces.IRepository`1 [[System.String, mscorlib version 2.0.0.0...etc]], Company.Project.Core"

does this help you out in any way?

Johan Leino
Sorry, should have been a little more descriptive! Your solution worked perfectly, thanks :)
David Kiff