开发者

StructureMap Plugins - easier way?

开发者 https://www.devze.com 2022-12-24 08:53 出处:网络
Let\'s say you have an interface of IModel that takes a pair of generics ... public interface IModel<TOne, TTwo>

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

public interface IModel<TOne, TTwo>
{
     TOne ConvertTo开发者_JAVA百科One(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"?


You could try this... it might work.

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

精彩评论

暂无评论...
验证码 换一张
取 消