Q:

StructureMap Open Generic Types

I have the following classes:
public interface IRenderer<T> 
{
    string Render(T obj);
}

public class Generic<T> { }

public class SampleGenericRenderer<T> : IRenderer<Generic<T>>
{
    public string Render(Generic<T> obj)
    {
        throw new NotImplementedException();
    }
}

I would like to be able to call StructureMap with 
ObjectFactory.GetInstance<IRenderer<Generic<string>>>(); and receive SampleGenericRenderer<string>.
I'm currently using the following registration and receiving this error when I call GetInstance. "Unable to cast object of type:

ConsoleApplication1.SampleGenericRenderer'1[ConsoleApplication1.Generic'1[System.String]]'
  to type
  'ConsoleApplication1.IRenderer'1[ConsoleApplication1.Generic'1[System.String]].

public class CoreRegistry : Registry
{
    public CoreRegistry()
    {
        Scan(assemblyScanner =>
        {
            assemblyScanner
                .AssemblyContainingType(typeof(IRenderer<>));
            assemblyScanner.AddAllTypesOf(typeof(IRenderer<>));
            assemblyScanner
                .ConnectImplementationsToTypesClosing(
                    typeof(IRenderer<>));
        });
    }
}

Is there any way to configure StructureMap so that it creates SampleGenericRenderer<string> instead of SampleGenericRenderer<Generic<string>>?
UPDATE: I ended up doing the type construction myself for this subset of dependencies. Because they combine contextual binding with a lot of unsupported generic bindings, this turned out to be the cleanest solution.

A:

I don't believe StructureMap has any mechanism for closing an inner generic parameter like this.
It's not ideal, but you might try creating your own IRegistrationConvention and whenever encountering a type that is a closed type of Generic<>, do the following:
var generic_t = typeof(Generic<>).MakeGenericType(type);
var sample_renderer_t = typeof(SampleGenericRenderer<>).MakeGenericType(type);
var renderer_t = typeof(IRenderer<>).MakeGenericType(generic_t);
graph.AddType(renderer_t, sample_renderer_t);

See http://docs.structuremap.net/ScanningAssemblies.htm#section11 for more details.

