tags:

views:

16

answers:

1

Let's say you have an interface of IModel that takes a pair of generics ...

public interface IModel<TOne, TTwo>
{
     TOne ConvertToOne(TTwo two);
     TTwo ConvertToTwo(TOne one);
}

and a class that implements this

public class OneTwo : IModel<SomethingOne, SomethingTwo>
{
   SomethingOne ConvertToOne(SomethingTwo two)
   { //zomg! nothing exciting!
   }

   ...
}

Nothing overly fancy. In my mapping configs, I have a list that looks kind of like this ...

For<IModel<SomethingOne, SomethingTwo>>().Use<OneTwo>();
For<IModel<SomeOne, SomeTwo>>().Use<AnotherClass>();

and so on. Based on DRY, I feel like this is the hard way to do this (there's 7 of them now, soon to be 20 or so). Anyway to do this "more better"?

+1  A: 

You could try this... it might work.

ObjectFactory.Initialize(x =>
{
    x.Scan(scan =>
    { 
        scan.AssemblyContainingType<Something>();
        scan.ConnectImplementationsToTypesClosing(typeof(IModel<,>));
    }
}
Jon Kruger