Skip to content

Allow extending genericInterfaceImplementations of DefaultObjectFactory #982

Description

@n9

Is your feature request related to a problem? Please describe.

It seems to me that there is currently no way to extend defaultGenericInterfaceImplementations of DefaultObjectFactory.

private readonly Dictionary<Type, Type> defaultGenericInterfaceImplementations = new()
{
{ typeof(IEnumerable<>), typeof(List<>) },
{ typeof(ICollection<>), typeof(List<>) },
{ typeof(IList<>), typeof(List<>) },
{ typeof(IDictionary<,>), typeof(Dictionary<,>) }
};

Mappings are only added to defaultNonGenericInterfaceImplementations.

foreach (var pair in mappings)
{
if (!pair.Key.IsAssignableFrom(pair.Value))
{
throw new InvalidOperationException($"Type '{pair.Value}' does not implement type '{pair.Key}'.");
}
defaultNonGenericInterfaceImplementations.Add(pair.Key, pair.Value);
}

Describe the solution you'd like

Provide a "simple" way to extend defaultGenericInterfaceImplementations.

Describe alternatives you've considered

Modify copy of DefaultObjectFactory.

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions