Register by complex naming convention in Castle Windsor

312 views Asked by At

I'm a newbie in the world of DI container. I am currently using Windsor Castle and I'm trying to configure my container by naming convention. Here is an example of what I'm trying to do:

interface INode{}
interface INodeType1: INode{}
interface INodeType2: INode{}

interface INodeConverter{}
class NodeType1Converter:INodeConverter{}
class NodeType2Converter:INodeConverter{}

It's an application in which users can build flowsheets by drag and dropping different kind of nodes. At a certain point, these nodes will have to be converted in a certain format and each node have their own specific way to be converted.

When I will resolve INodeType1, I would like to receive an instance of NodeType1Converter. When INodeType2 --> NodeType2Converter, ...

I tried to register it using the WithService.Select but without success:

container.Register(Classes.FromThisAssembly()
                .InSameNamespaceAs<INodeConverter>()
                .WithService.Select((type, types) => type.Name.EndsWith("Converter")  && type.Name .StartsWith ("don't know what to do here?!?")
                                                    ? new[] { type.BaseType }
                                                    : Enumerable.Empty<Type>()));

Can anobody help me?

Thank you, Philippe

0

There are 0 answers