Using StructureMap, We have all types that are auto registered.

public class MessageRegistry : Registry
{
    public MessageRegistry(){
        Scan(x =>
             {
                 x.AssemblyContainingType(typeof (FormatHelper));
                 x.ConnectImplementationsToTypesClosing(typeof (IMessage<>));
             });
    }
}

So, in case we look for IMessage<Currency>, it will find below type:

CurrencyMessageHandler : IMessage<Currency>
{
    public CurrencyMessageHandler(ISession instance) 
}

As to the constructor parameter type ISession, we like it to be auto wired, however, we have got more than 1 implementation like SqlSession and OracleSession. In this case, we would like to pass SqlSession as constructor parameter.

How to specify named instance as constructor parameter in this case?

Much appreciated.

1

There are 1 answers

0
pdalbe01 On

I had this same exact problem and I solved it by excluding the type from the scan and then custom configuring it:

Scan(scan => scan.Exclude(t => t == typeof(CurrencyMessageHandler));

and then:

For<IMessage<Currency>>.Add<CurrencyMessageHandler>()
     .Ctor<ISession>.Is(a => a.TheInstanceNamed("SqlServer"));