views:

29

answers:

0

I need to be able to, at runtime, load two classes that share an unknown type, like this:

interface IProducer<out A>
{
    public A CookOne();
}

interface IConsumer<in A>
{
    public void EatOne(A food);
}

The entire list of possible involved types can't be known at compile time because they don't exist yet. The software that uses these types is something like this:

interface IStrategyFactory<A>
{
    public IStrategy<A> MakeAStrategy(IProducer<A> producer, IConsumer<A> consumer);
}

interface IStrategy<A>
{
    public void DoSomething();;
}

How can I load external binary code (from two different sources) and pass them to the factory (or wherever else) in a type-safe manner, so that I can't, for example, pass in a IProducer and an IConsumer?

The best resource I can find on this so far is http://codebetter.com/blogs/glenn.block/archive/2009/08/20/open-generic-support-in-mef.aspx

Optimally the program itself would have types like this:

interface IStrategyFactory<A>
{
    public IStrategy MakeAStrategy(IProducer<A> producer, IConsumer<A> consumer);
}

interface IStrategy
{
    public void DoSomething();;
}