I have an object that contains a property:
public Dictionary<string, Dictionary<string, List<ContextMenuItemModel>>> ContextMenuModel { get; set; }
How do I use Spring.Net to configure this property?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, configuring this in xml isn’t pretty, consider switching to Spring.Net code config to configure your spring context in C#.
Anyway, to do this in xml, you use the constructors of the generic .net collections. For instance,
List<T>takes anIList<T>constructor, so you can configure a list of strings as follows:Note that in xml you have to use
<, because using<isn’t legal xml. Setting generic collection values is discussed in the Spring.net docs.A generic
Dictionary<string, System.Collections.Generic.List<string>>can be configured in a similar manner, which is also discussed in this answer:And you probably see the next one coming now:
Which can be injected:
This isn’t really pretty, but you can slightly improve the readability of your xml using type aliases.