Can objects of generic types be created via instance factory methods?

6 views
Skip to first unread message

Intanda

unread,
Jan 16, 2012, 3:49:37 AM1/16/12
to Castle Project Users
Hi

Being new to both this forum and Castle I apologies in advance if the
following question has already been asked and answered

Based on the below contrived example can generic types, such as
TestGenericType, be created via instance factory methods when using
the Windsor Castle IoC framework? ( NB - Our current method of
component configuration relies on the XML based approach rather then
the fluent interface. )


//Example Generic Object
public class TestGenericObject<T, U>
{
public TestGenericObject()
{
}

private IList<T> someGenericList = new List<T>();

private IDictionary<string, U> someStringKeyedDictionary =
new Dictionary<string, U>();

public IList<T> SomeGenericList
{
//get; set; someGenericList
}

public IDictionary<string, U> SomeStringKeyedDictionary
{
//get; set someStringKeyedDictionary;
}
}


//Example Factory
public class TestGenericObjectFactory
{
public static TestGenericObject<V, W> StaticCreateInstance<V, W>()
{
return new TestGenericObject<V, W>();
}
}

Thanks in advance

Krzysztof Koźmic

unread,
Jan 25, 2012, 7:00:54 PM1/25/12
to castle-pro...@googlegroups.com
Sure it can, but since you don't know the actual, closed type, your
factory will need to do some reflection to do it.

Hence I don't think you can do it in XML.

Reply all
Reply to author
Forward
0 new messages