4 thoughts on “Web API and Interface Parameters

  1. hfarouk says:

    Tried to run the code provided on GitHub but it is not working as expected. The Service locator will pick up/resolve an interface to the last registered concrete class not based on the given serialized type(i.e json payload).

    • brettedotnet says:


      Sorry you had issues with the code. Could you provide to me your container registrations so I can better understand what went wrong? Are you using named registrations?

      Please let me know and I will do what I can to correct.


  2. jmartinzone says:

    Thank you for this article. I looked around for several hours yesterday looking at various solutions to this situation. Though I dd not go full “generic” I did adapt it to cover the cases I needed with a single converter implementation which took the Interface Type and Implementation class:

    public class MyCustomConverter : CustomCreationConverter where C: I , new()

    I then registered an instance of the converter for each interface/implementation pair:
    GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new MyCustomConverter());
    GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new MyCustomConverter());
    GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new MyCustomConverter());

    Thanks for the guidance. I’d still be working on this today without it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: