Abstract factory mappings

Mar 22, 2011 at 11:38 AM

Hi,

I have two view models:

        public class ViewModel1
        {
            [ResolveConstructor]
            public ViewModel(IElementFactory elementFactory)
            {
              ... 
            }
        }

        public class ViewModel2
        {
            [ResolveConstructor]
            public ViewModel2(IElementFactory elementFactory)
            {
             ...  
            }
        }

And I have two classes that inherit IElementFactory: DefaultElementFactory, SpecialElementFactory. (Basically AbstractFactory pattern).

How can I specify in assembly info that I want to use DefaultElementFactory for ViewModel1, but SpecialElementFactory for ViewModel2?

I know that I can use:

[assembly: DefineService(typeof(IElementFactory), typeof(ElementDefaultFactory),"DefaultFactory")]
[assembly: DefineService(typeof(IElementFactory), typeof(SpecialElementFactory),"SpecialFactory")]

and then code will look like:

        public class ViewModel2
{
[ResolveConstructor]
public ViewModel2([ResolveResource("SpecialFactory")]IElementFactory elementFactory)
{
...
}
}

But I don't like the string approach so much, and would prefer an assembly info attribute like:
[assembly: DefineConstructor(typeof(ViewModel2),typeof(IElementFactory), typeof(SpecialElementFactory))]

Is there such a thing or something equivalent?
Coordinator
Apr 11, 2011 at 11:32 AM

Hi, sorry for delay in replying .. now, unfortunately currently there is nothing like DefineConstructor attribute functionality - but it's an interesting idea that I'll look to develop on. All the same, it is possible to extent the underlying infrastructure to get rid of the string identifiers - consider inheriting from the base class, and use the type's full name as being the underlying identifier. 

Cheers,
Rishi