Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Unity (2.x) to use Moq as implementation via app.config

I am using Unity for IOC. I would like to configure the creation of moq objects using the app.config. My config looks some like this:

<unity xmlns="schemas.microsoft.com/practices/2010/unity">
  <container>
    <register type="Namespace1.IFoo, FooInterface"                   
              mapTo="Namespace2.FooImp, FooImplementation">
    </register>
</container>
</unity>

I am looking for a technique to specify a configuration some like this:

<unity xmlns="schemas.microsoft.com/practices/2010/unity">
  <container>
    <register type="Namespace1.IFoo, FooInterface"                   
              mapTo="Moq.Mock<IFoo>, Moq">
    </register>
</container>
</unity>

I Know that I have to access .Object property of a Mock but this sample is just meant to explain what I want to do.

In other words: I do not want to use code to configure unity to use moq. An option would of course be to create some helpers that can be used in general.

like image 820
Jaster Avatar asked Dec 04 '25 16:12

Jaster


1 Answers

After no one could help I figured something out.

Use a Factory for moq and add a factory resolution via unity

sample goes here

like image 116
Jaster Avatar answered Dec 06 '25 15:12

Jaster