XML Unity configuration with generalists

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

public interface IRepository<T> {}

public class OrderRepository : IRepository { }

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

      

I would like to add the order repository to the DispatchOrderProcess class using Unity XML config. So far I have something like this:

                                   

            <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>

      

+2


source to share


1 answer


... and your problem?

I've been doing a little bit of generics work lately and have had some syntax problems. Apparently I didn't mean to say oneness what type T is, something like:



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

      

will it help you in any way?

+2


source







All Articles