1

I am learning NativeScript + Angular2 with ServiceStack in C# as the backend.

For the app, I generated TypeScript classes using the typescript-ref command, for use with the JsonServiceClient in ServiceStack:

>typescript-ref http://192.168.0.147:8080 RestApi

It all looked sweet and dandy, until I discovered that it seems to ignore that the ServiceStack Services and Response DTOs are in different namespaces on the .NET side:

enter image description here

I have different branches of services, where the handlers for each service might differ slightly between the branches. This works well in ServiceStack, the Login and handlers work just as expected.

So, on the app/NativeScript/Angular2-side, I used the typescript-ref and generated the restapi.dtos.ts. The problem is it skips the namespace difference and just creates duplicate classes instead (from VSCode):

enter image description here

The backend WS in ServiceStack is built in this "branched" fashion so I don't have to start different services on different ports, but rather gather all of them on one port and keep it simple and clear.

Can my problem be remedied?

1 Answer 1

2

You should never rely on .NET namespaces in your public facing Services Contract. It's supported in .NET Clients but not in any other language which requires that each DTO be uniquely named.

In general your DTOs should be unique within your entire SOA boundary so that there's only 1 Test DTO which maps to a single schema definition which ensures that when it's sent through a Service Gateway, resolved through Service Discovery, published to a MQ Server, etc it only maps to a single DTO contract.

8
  • Right, I have to rethink this then. Do you know if there is a way to host multiple APIs on same port, not using a classic webserver for reverse proxy? I'm selfhosting.
    – Ted
    Feb 15, 2018 at 5:46
  • @Ted Not on the same port, so you'd need to use a reverse proxy if you want multiple instances to appear from the same host.
    – mythz
    Feb 15, 2018 at 7:19
  • Alright, thx. Maybe it would be a great future feature to be able to start one AppHost on one port, but define multiple APIs, so the AppHost could specify more than one assembly in the constructor, or something like it? So instead of: public AppHost(IModuleController moduleController, IContactModule contactModule) : base("HttpListener Self-Host", typeof(AppHost).Assembly), maybe something like AddAssemblyWithServices(Assembly assembly, string prefix) where prefix prefixes all the services in the assembly, so /api/<prefix>/<service> ? =)
    – Ted
    Feb 15, 2018 at 7:41
  • @Ted You can specify multiple dlls in AppHost Constructor. IMO routes should be explicitly on each Request DTO since it's part of the service contract, but there's also Auto Route Generation Strategies and ways to dynamically modify routes by overriding GetRouteAttributes in your AppHost. Other feature requests can be added to UserVoice so interest can be measured.
    – mythz
    Feb 15, 2018 at 7:58
  • OK, but inside each Assembly containing services, the DTOs/services must still have unique names (because its the same "service contract"?). So, in the case of typeof(ServicesFromDll1).Assembly, typeof(ServicesFromDll2).Assembly, service names in ServicesFromDll1 cannot have any DTO etc with the same name is in ServicesFromDll2, as per your answer above?
    – Ted
    Feb 15, 2018 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.