Pluggable endpoints

The model and userinterface in our (web-)application can be customized for each customer. For example.

public class Person {
  public string LastName
  ..
}

public class PersonForCustomerX : Person {
  public string BirthCountry
  ..
}

In the application we have a button ‘EditPerson’, the default implementation should load and save the Person class, but when the plugin is loaded with the PersonForCustomerX the load and save function should also load/store the additional properties in the PersonForCustomerX class.

I could just create separate endpoints for both implementations. But is it also possible to use a single endpoint and let servicestack return the correct implementation via injection?

Thanks
Marco

As long as the PersonForCustomerX decends from Person, this should be no problem.

Ok, but I assume I have to configure this somewhere…tips how?

You shouldn’t rely on inheritance in DTOs, the metadata services won’t be able to report the inherited classes you’ll also need to make the base class abstract in order to work in different languages that Add ServiceStack Reference supports.

I’d recommend either having different typed services or adding a Dictionary on the Person class to hold the additional properties and avoid inheritance.

As mythz pointed out, inheritance in DTOs is not visible in the Metadata services. You can only expose the base DTO in the metadata. Any specific descendant is not ‘shown’. The results work anyway - no magic involved.

I personally do not see that as a bad thing, and it would be useful to document that specific implementations can provided extended information on the specific situation.

A typed service is probably the best choice if you need multiple versions. That way, you would even be able to provide specific implementation-details to a customer specific result - think of a PersonNumber that requires specific validation for a specific customer. This would also be the best coice for separation of concerns.

Using a dictionary would be my last resort, since it would mean you’ll give up all type checking, property validations and so on. You can ofcourse use a dictionary for customer specific references you only want to store for convenience (references from and for external systems)

Hope this helps.

Thanks! At this moment I’ve got only javascript clients, so metadata services is not important.